   [C++, DX9] Window Resize problem
  Function organizing parameters:D3DPRESENT_PARAMETERS InitializeParameters(){D3DPRESENT_PARAMETERS dx_PresParams;ZeroMemory( &dx_PresParams, sizeof(dx_PresParams) );dx_PresParams.Windowed = windowed;dx_PresParams.SwapEffect = D3DSWAPEFFECT_DISCARD;dx_PresParams.BackBufferFormat = display.Format;dx_PresParams.EnableAutoDepthStencil = TRUE;if(SUCCEEDED(object->CheckDeviceFormat(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,display.Format,D3DUSAGE_DEPTHSTENCIL,D3DRTYPE_SURFACE,D3DFMT_D24X8))) dx_PresParams.AutoDepthStencilFormat = D3DFMT_D24X8;else if(SUCCEEDED(object->CheckDeviceFormat(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,display.Format,D3DUSAGE_DEPTHSTENCIL,D3DRTYPE_SURFACE,D3DFMT_D24S8))) dx_PresParams.AutoDepthStencilFormat = D3DFMT_D24S8;else if(SUCCEEDED(object->CheckDeviceFormat(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,display.Format,D3DUSAGE_DEPTHSTENCIL,D3DRTYPE_SURFACE,D3DFMT_D16))) dx_PresParams.AutoDepthStencilFormat = D3DFMT_D16;dx_PresParams.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;dx_PresParams.Flags=D3DCREATE_PUREDEVICE;if(!windowed){dx_PresParams.BackBufferWidth=(int)WIDTH;dx_PresParams.BackBufferHeight=(int)HEIGHT;}return dx_PresParams;}Window call:LRESULT CALLBACK Window_Call(HWND han_Wind,UINT msg,WPARAM parameter1,LPARAM parameter2) {if(msg==WM_SIZE){sprite->Release();sprite=NULL;device->Reset(&InitializeParameters());D3DXCreateSprite(device, &sprite);}return DefWindowProc(han_Wind,msg,parameter1,parameter2);}After resizing window sprite doesn't get created, and pointer remains NULL. Anyone have idea why this happens?   
  Do you get a WM_SIZE message?Does D3DXCreateSprite() succeed?Does Reset() succeed?Are you aware you don't need to release the sprite, you can just call OnLostDevice() and OnResetDevice()?Do the Debug Runtimes say anything?   ;Quote:Original post by Evil SteveDo you get a WM_SIZE message?Yes I do.Quote:Original post by Evil SteveDoes D3DXCreateSprite() succeed?Seems not.Quote:Original post by Evil SteveDoes Reset() succeed?Seems not.Quote:Original post by Evil SteveDo the Debug Runtimes say anything?Direct3D9: (ERROR) :All user created stateblocks must be freed before ResetEx can succeed. ResetEx Fails.Direct3D9: (ERROR) :ResetEx failed and ResetEx/TestCooperativeLevel/Release are the only legal APIs to be called subsequentlyDirect3D9: (INFO) :DDI threading stoppedDirect3D9: (ERROR) :Device is in an invalid state. Only Reset, TestCooperativeLevel, CheckDeviceState or Release could be calledI've tried to Release but it doesn't seem to help.if(msg==WM_SIZE){for(unsigned int i=0; i<Textures.size(); i++) delete Textures;delete Sprite_Chat_Bar;Sprite_Chat_Bar=NULL;delete Sprite_Chat_Messages;Sprite_Chat_Messages=NULL;delete Sprite_Login_Back;Sprite_Login_Back=NULL;delete Sprite_LoginAcct_Input;Sprite_LoginAcct_Input=NULL;delete Sprite_LoginPass_Input;Sprite_LoginPass_Input=NULL;delete Sprite_Login_Button;Sprite_Login_Button=NULL;delete Sprite_Button_OK;Sprite_Button_OK=NULL;delete Sprite_CharName_Input;Sprite_CharName_Input=NULL;delete Sprite_Char1_Back;Sprite_Char1_Back=NULL;delete Sprite_Char2_Back;Sprite_Char2_Back=NULL;delete Sprite_Char_BtnNew;Sprite_Char_BtnNew=NULL;delete Sprite_Char_BtnDel;Sprite_Char_BtnDel=NULL;delete Sprite_Char_BtnEnt;Sprite_Char_BtnEnt=NULL;delete buttonLogin;buttonLogin=NULL;sprite->Release();sprite=NULL;//font->Release();//chatfont->Release();device->Reset(&InitializeParameters());D3DXCreateSprite(device, &sprite);CreateSprites();buttonLogin=new Button("buttonLogin",Vector3((WIDTH-300)/2+215,HEIGHT-160,0),Vector3(74,45,7),Login);}Sprite_Chat_Bar and etc have deconstructor to release texture.   ;  Pickle, you are in.If you're interested, read up on RAII patterns.  They can be really useful in situations where you need to Begin() something and then End() it sometime later (or locking/unlocking things).  Then you're never caught with your knickers around your ankles when you have to do something like reset the universe.   ;Quote:Original post by RipizDirect3D9: (ERROR) :All user created stateblocks must be freed before ResetEx can succeed. ResetEx Fails.Direct3D9: (ERROR) :ResetEx failed and ResetEx/TestCooperativeLevel/Release are the only legal APIs to be called subsequentlyDirect3D9: (INFO) :DDI threading stoppedDirect3D9: (ERROR) :Device is in an invalid state. Only Reset, TestCooperativeLevel, CheckDeviceState or Release could be calledIt's exactly as the error says - you have some resources that aren't freed. You'll need to make sure that all of your default pool resources are Release()'d, and all D3DX objects have OnLostDevice() called on them (Well, the objects that have that member function anyway).   ;  I think I found it. Thanks. Seems I'll have to reload models too, as they disappear after resizing =/   ;Quote:Original post by RipizI think I found it. Thanks. Seems I'll have to reload models too, as they disappear after resizing =/If by models you mean ID3DXMesh, then you only need to Release() and re-create them if they're created in the default pool (I.e. don't use D3DXMESH_MANAGED or D3DXMESH_SYSTEMMEM for the flags passed to D3DXLoadMeshFromX()).   ;  What flag to use then? D3DXMESH_DEFAULT doesn't exist   ;Quote:Original post by RipizWhat flag to use then? D3DXMESH_DEFAULT doesn't existIf you want a default pool mesh, pass 0 for the flags (Or rather, not D3DXMESH_MANAGED or D3DXMESH_SYSTEMMEM).Unless you have a good reason (E.g. you're doing a dynamic mesh), you probably want D3DXMESH_MANAGED.   ;  You shouldn't just release/reset/recreate.  The correct approach is to check for a D3DERR_DEVICELOST HRESULT from your Present call, then set a flag that you've lost the device.  At the start of each frame test the value of this flag to see if you lost the device on the previous frame.  If so, call IDirect3DDevice9::TestCooperativeLevel and check it's HRESULT.  D3DERR_DEVICELOST means that the device is still lost so do nothing and skip the frame.  D3DERR_DEVICENOTRESET means that the device is now ready to be reset, so release all resources and call Reset, but skip rendering the frame.  D3D_OK means that the device has completed it's reset OK so you can now recreate the resources, clear your device lost flag, and continue rendering as normal.  D3DERR_DRIVERINTERNALERROR means that something bad happened so you'll probably need to abort the app.This way you'll have a single code path that you can use for all situations in which you might lose the device and you won't need special handling all over the shop.   