DI object not releasing properly

Started by
3 comments, last by Sfpiano 20 years, 9 months ago
Here''s my init code
if(FAILED(pDI->CreateDevice(GUID_SysKeyboard,&pKeyboard,NULL)))
		return E_FAIL;

	if(FAILED(pKeyboard->SetDataFormat(&c_dfDIKeyboard)))
		return E_FAIL;

	if(FAILED(pKeyboard->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | 
												DISCL_NONEXCLUSIVE)))
		return E_FAIL;

	if(FAILED(pKeyboard->Acquire()))
		return E_FAIL; 
And then in my deconstructor I have :

pKeyboard->Unacquire();
	SAFE_RELEASE(pKeyboard);

	SAFE_RELEASE(pDI)
 
However when I run the debugger, I get: Direct3D9: (INFO) :MemFini! Direct3D9: (ERROR) :Memory still allocated! Alloc count = 145 Direct3D9: (ERROR) :Current Process (pid) = 00000c9c And I know it''s in reference to the keyboard because if I dont init the keyboard I don''t get the error.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
Advertisement
1b) Try turning up the DirectInput slider and enabling output messages for all device types in the control panel and see if you get any more informative output.

1b) As a test I just modified one of the DirectInput samples so that it deliberately didn''t release a device object, and I got a message in my debug spew saying: "DINPUT8: unloaded before all objects released. (cRef:4)".


2a) I find the fact that you''re getting messages regarding DirectInput leaks from Direct3D DLLs highly odd, even unlikely. I suspect there''s something else going on here, maybe to do with some shared control path between your D3D and DI code (e.g. D3D objects only being created when

2b) Unless a particular driver or the ActionMap display stuff is using D3D internally.


3) Is that deconstructor in a class whose object is a global or static variable ? If so, then the deconstructor might be called after WinMain exits.

Try breakpointing the deconstructor (a) to make sure it''s being called [i.e. issues with virtual destructors etc] and (b) to single step the DI calls to see if the messages you see originate there.


4) For debugging purposes, try modifying the SAFE_RELEASE macro you use to check the return value from each Release() call [and maybe causing a breakpoint] to see if there are any references still held by any objects being released. If there are, it indicates that one of the subordinate/child objects wasn''t released or has AddRef''d somewhere


--
Simon O''Connor
ex -Creative Asylum
Programmer &
Microsoft MVP

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Are you sure it''s DirectInput? From the debug message it looks like some Direct3D object is not freed up properly.
I know it stopped giving me that error when I commented out the keyboard, but now it is giving me the error still, even though I don''t remember changing anything... Now I have to track this one down. Any suggestions as to how to debug? I know you can set a breakpoint at teh Alloc count it gives me, but when I do that my program crashes because my application loses focus, so I have no way of determing where the error is.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
Ok, I think I might have it. I found that I''m not releasing my D3DSurface. However, when I try to release it, it gives me an access violation. It says the value at the time is 0xcdcdcdcd.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."

This topic is closed to new replies.

Advertisement