Skip to main content
gamedev.net
🔒 Locked

Reset() on D3DERR_DEVICENOTRESET

Started by RelisH Dec 23, 2001 at 11:55 PM 1 replies 450+ views
Original Post
RelisH
RelisH
I''ve just noticed a memory leak that ocurrs during reset when there is D3DERR_DEVICENOTRESET (e.g., after I alt tab and then maximize the program, which runs in full screen). This little bit of code tries to reset directx so that it will run after the user has alt-tabbed or done any sort of minimizing/maximizing in fullscreen. It works fine, but I''ve noticed a memory leak, and I haven''t a clue as to what it''s from. I know it''s not from any of my vertex buffers or index buffers since I''ve made a call to the class to which the buffers belong which would release the buffers, and also because the reset is successful, and DirectX whines if I don''t release my D3DPOOL_DEFAULT buffers before reset. Is there any source for this memory leak that anyone may know of? Here''s a snippet of the code that handles what I''m talking about: SAFE_RELEASE(g_pBackSurf); g_BGCube.KillBuffers(); for (int i = 0; i < CUBE_MAX; i++){ g_CubeSet.m_CubeArray.KillBuffers(); } r = g_pDevice->Reset(&g_SavedPresParams); KillBuffers() is the method that kills(releases) the buffers of the cubes in the game (the game is Tetris Attack by the way) Am I forgetting to release anything here?
-RelisH!
S1CA
S1CA
Do you remember to release for the implicit references too ?

When you set a resource as the "current" one in use (SetTexture, SetStreamSource etc), D3D increments its reference count. This is so that you can''t Release() something which the hardware currently refers to (D3D calls don''t happen immediately, and they aren''t blocking - they get buffered up - the hardware may carry them out some time down the line).


If you''ve SetTexture() for a stage, if you need to Release() the texture which is being used for that stage (say for a Reset operation), you should set the texture for that stage to NULL, i.e. m_pDevice->SetTexture(stage, NULL).

The same goes for vertex buffers. If a buffer is bound to a stream, it should be unbound before you release it!. i.e. m_pDevice->SetStreamSource(stream, NULL, 0).

And finally for index buffers: m_pDevice->SetIndices( NULL, 0 ).



--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
RelisH
RelisH
No luck =/

Ok, these are the changes I've made:
Added SetStreamSource(0,0,0), SetIndices(0,0) (where applicable) and SetTexture(0,0) to the killbuffers() method for each of the classes
Hrrm, what am I missing?
The first time I minimize and maximize the window, the number of unreleased bytes is roughly 250000, then every extra time I alt-tab, it increases by 2 KB.

Argh, so frustrating!


Edited by - RelisH on December 24, 2001 10:59:11 AM
-RelisH!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.