PDA

View Full Version : InvalidPointer Exception when Freeing ?



Avatar
10-01-2005, 09:12 PM
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 :


destructor TBillBoard.Free;
Begin
SafeDelete(_VB);
SafeDelete(_Texture);
end;

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

savage
10-01-2005, 09:22 PM
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?

Clootie
10-01-2005, 09:36 PM
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...

Sly
10-01-2005, 09:41 PM
Why are you overriding Free? I believe the documentation says that you should never override Free. Override Destroy instead.

destructor TBillBoard.Destroy;
begin
SafeDelete(_VB);
SafeDelete(_Texture);
inherited;
end;


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

destructor TBillBoard.Destroy;
begin
_VB := nil;
_Texture := nil;
inherited;
end;


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

Avatar
10-01-2005, 09:48 PM
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 :D

Clootie
10-01-2005, 10:29 PM
Clootie > I'm almost sure they are Interfaces :D
I'm sure they are :D

Avatar
10-01-2005, 10:47 PM
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 :)