Results 1 to 7 of 7

Thread: InvalidPointer Exception when Freeing ?

  1. #1

    InvalidPointer Exception when Freeing ?

    Hi all !

    I've been messing with that Exception for a little time and I can't stand it anymore ^^

    When I'm freeing my object(which is a Billboard), the program may crash (for the statistics, 3 crashes for 10 runs) and throw an "Invalid Pointer Exception".

    The problem is that it is not crashing on a specific method, but at the last line of the destructor ... I can swap the lines, it'll still crash on the last one.

    Here is my destructor :

    [pascal]
    destructor TBillBoard.Free;
    Begin
    SafeDelete(_VB);
    SafeDelete(_Texture);
    end;[/pascal]

    The SafeDelete method is the one used by Clootie (thanks to him ^^). But anyway, I don't think the Release may crash the program ...

    Any idea on what could be the problem ?

    Thanks in advance

    Avatar

  2. #2

    InvalidPointer Exception when Freeing ?

    I had something similar with a DirectPlay sample I helped tux with, and it turned out to be the way the COM Objects were created,

    Can you provide a sample application that shows it happening?
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  3. #3

    InvalidPointer Exception when Freeing ?

    I hope you are really using SAFE_RELEASE on interfaces :roll:
    Last line of destructor means what probably compiler internally tries to free other interfaces of your class...
    There are only 10 types of people in this world; those who understand binary and those who don't.

  4. #4

    InvalidPointer Exception when Freeing ?

    Why are you overriding Free? I believe the documentation says that you should never override Free. Override Destroy instead.

    [pascal]destructor TBillBoard.Destroy;
    begin
    SafeDelete(_VB);
    SafeDelete(_Texture);
    inherited;
    end;
    [/pascal]

    By the way, I always use the following to free my COM objects.

    [pascal]destructor TBillBoard.Destroy;
    begin
    _VB := nil;
    _Texture := nil;
    inherited;
    end;
    [/pascal]

    Setting a COM object pointer to nil releases the COM object.

  5. #5

    InvalidPointer Exception when Freeing ?

    I just tried to change Free to Destroy but it didn't changed anything (even with adding inherited at the end).

    Clootie > I'm almost sure they are Interfaces

  6. #6

    InvalidPointer Exception when Freeing ?

    Quote Originally Posted by Avatar
    Clootie > I'm almost sure they are Interfaces
    I'm sure they are
    There are only 10 types of people in this world; those who understand binary and those who don't.

  7. #7

    InvalidPointer Exception when Freeing ?

    Problem solved thanks to Savage.

    It seems that I forgot to override the destroy function :roll:

    On the top of that, my objects weren't really well created ^^

    Anyway thanks a lot to Savage

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •