Archived

This topic is now archived and is closed to further replies.

Mort

DirectX objects dependencies upon eachother

Recommended Posts

I''ve become quite confused now. I''ve created a graphics engine, that until now only runs windowed mode (To ease the debugging of it), but I''ve reached the point where I was going to implement a fullscreen feature too. Now, I come across a problem with destroying my DirectX objects, to create new ones. It seems that some of the objects are dependent on eachother, and has to be Released in the right order. It also seems to me that some of the objects are actually the same COM object as other ones. As an example I discovered that I couldn''t destroy my Primary and Secondary drawing surfaces before I destroyed my DrawingDevice. If I did, the final Release of the DrawingDevice would result in an access violation inside a DirectX DLL. I also discovered that if I Released my Direct3D object, the referance count of my DirectDraw object would also decrement. That in itself wasn''t all. After having Released both my Direct3D and DirectDraw objects, I got a major error, after re-creating my DirectDraw object, and trying to set it''s cooperative mode to fullscreen. When I tried this, the instruction pointer jumped to another function, not in any way related to DirectDraw object. I can only guess that DirectX has invalidated my CPU registers, resulting in the instruction pointer becoming invalid. Can some of you explain to me which DirectX objects are dependent on eachother, and why I am unable to destroy my DirectX objects, and then create them again ? - Mort

Share this post


Link to post
Share on other sites
There are several semi-related points here.

Firstly, whilst the docs never actually state it, you should always try to release DX interfaces in the order that you created them. It makes life much easier in the end.

You are quite right when you say that some interfaces actually relate to the same object. Thats why you can write

lpDDraw7->QueryInterface(IDirect3D7, ....)

for example. It means you are asking the DirectDraw interface if it has a Direct3D interface for you to use. You don''t need to worry about this as long as you stick to releasing interfaces in the correct order.

Any interface that is created using QueryInterface() will relate to the same object that you called the function from. Thats one form of dependency.

Anything you create using an interfaces Create* methods is probably dependent. For example if you call

lpDDraw7->CreateSurface(...)

then the surface you create is dependent on the existence of the DirectDraw interface and will maintain a reference to it.

I suspect that the reason that you can''t recreate the interfaces is that you didn''t manage to destroy them correctly in the first place but thats just a guess.


Regards,
Ralph Potter
ralph.potter@digital-magi.com, http://www.digital-magi.com

Share this post


Link to post
Share on other sites
quote:
Original post by digital-magi
Firstly, whilst the docs never actually state it, you should always try to release DX interfaces in the order that you created them. It makes life much easier in the end.



Is that in order or in REVERSE-order? I thought it made sense for reverse order... What is your opinion on the matter?

-Chris Bennett of Dwarfsoft - Site:"The Philosophers' Stone of Programming Alchemy" - IOL
The future of RPGs - Thanks to all the goblins over in our little Game Design Corner niche
          

Share this post


Link to post
Share on other sites