Advertisement

Help needed with linking....

Started by August 08, 2001 11:04 AM
30 comments, last by Moe 23 years, 5 months ago
Anyone? I really think that its something deeper thats causing the problem.
Whenever something takes a long time to debug, its usually something stupid.

In D3D.cpp change this

    if(lpd3ddevice != NULL)         lpd3ddevice->Release();    if(lpd3d != NULL)        lpd3d->Release();    


to this

  	if(lpd3ddevice != NULL)     {		lpd3ddevice->Release();		lpd3ddevice = NULL;	}    if(lpd3d != NULL)    {		lpd3d->Release();		lpd3d = NULL;    }  


The problem was that you were calling lpd3ddevice->Release() twice. The first time it would work, whereas the second time it would crash. Did I mention I have never used Direct3D?

Don't feel bad, I've had my share of stupid bugs that have cost companies a lot of money with me scratching my head.

Email me if you have any other problems.

EDIT-fix source tags

Edited by - Big B on August 19, 2001 8:51:57 PM
Advertisement
This kind of error is why a lot of people use a ''SAFE_RELEASE'' macro, which is usually something like:

#define SAFE_RELEASE (x) { if (x) { (x)->Release(); x = NULL; }}

This tends to stop you making these sorts of mistakes. Although, you probably also need to look into why your code tries to release something twice, rather than just patching it up so it doesn''t break.
Thanks for that. I will have to try it out as soon as I get home. Sorry for not getting back sooner, my internet has been down since thursday.

Also, the reason for the shutdown code being called twice was that I had a destructor that would call it in case it wasn''t called already. I also had to fix up a few other things in my program (like the main loop wasn''t being called).

So did that also fix the memory leak? (All I did to find it was crank the DX8 debug level up to the max, then debug it.).
It appears that there might be something wrong with that SAFE_RELEASE macro, or the way I am using it:
  SAFE_RELEASE(lpd3ddevice);SAFE_RELEASE(lpd3d);  

Now for some reason it gives me these errors:
  error C2065: ''x'' : undeclared identifiererror C2143: syntax error : missing '';'' before ''{''error C2227: left of ''->Release'' must point to class/struct/unionerror C2143: syntax error : missing '';'' before ''{''error C2227: left of ''->Release'' must point to class/struct/union  

Let me guess, there is a semicolon missing somewhere...
Try removing the space between SAFE_RELEASE and the (x).

Or better still, use an inline function:
inline void SafeRelease(IUnknown* ptr){    if (ptr)    {        ptr->Release();        ptr = NULL;    }    else    {        // Print diagnostic message indicating double-freeing?    }} 

If it doesn''t work with IUnknown*, make it a template function instead.
Advertisement
Heh, taking out the space made things work like a charm. There is one last (and hopefully last) thing that I am having trouble with. There appears to be a 2304 byte mem leak when the program is run in fullscreen mode, and in fullscreen mode only. Is there something extra that I should be releasing when I use fullscreen mode?
Doesn''t your memory-checking tool track where the leaked memory was allocated from?

There shouldn''t need to be anything extra to release in fullscreen mode. You just release whatever you acquire, regardless of mode.
I am not using any specific memory tracking tool other than debugging with VC++ and I have the DX8 debug level cranked to the maximum.

Edited by - Moe on August 23, 2001 10:30:07 PM
Nothing wrong with #pragma once unless you''re really worried about porting. The ifdefs are hard to maintain. Or harder, anyway. I always tend to forget the #endif at the end.

Hmm...as for COM. How about writing an interface pointer class? That''ll take care of all your release worries if you get lots of those errors...
VK

This topic is closed to new replies.

Advertisement