tags:

views:

115

answers:

1

Hello Fellow,i'm new with this thing named interface and DirectX. I'm hooking a DirectX Interface from a certain game and i'm using the DirectX to Draw My Own stuff,like textures and Fonts. My problem are that: When the program call the Hooked Reset Function of the Device,i need to clear all my things from the memory,the Com Interfaces.If i not clear,after the Reset event are called,the Game just try to create a new surface calling d3dDierctx9Create but its fail and just make a error and close the game.

I think that i just need to clear all the things before the Reset Event,its is explained on Msdn.

+10  A: 

You don't free an interface. It's reference-counted and managed by the compiler. Let it go out of scope, assign a different interface to the variable, or assign nil to it, and the compiler will generate a call to its _Release method automatically so it can clean itself up when its reference count drops to 0.

Mason Wheeler
So with directx resources, you usually either call 'onResetDevice' on them if they support it, or recreate them and reassign them to the Delphi variable. That will automatically free the original resource, like Mason said... _you just have to be really careful not to retain the resource in another variable somewhere, as that will prevent the resource from being freed_ (i.e. referenceCount > 0). Usually using some sort of wrapper objects that manages the resource makes this a bit easier.
Paul-Jan