Thanks for the quick reply.
I'm not using SetTexture anywhere. I added the render state's to the reset function but the same issue occurs.
I forgot to add the debug output in my original post, my apologies. But here it is.
If I run the application and then quit it terms cleanly and I loose no memory. I do get a couple warnings about redundant SetRenderStates - but I can google those later. However, if I force a device reset, recreate the texture, I loose 960 bytes of memory. But, if I force a device reset and do not recreate the texture I get a lot of:
Quote:
First-chance exception at 0x76cdb09e in blank.exe: Microsoft C++ exception: long at memory location 0x001af990..
Direct3D9: (ERROR) :State block release failed.
Direct3D9: (ERROR) :State block handle is greater than available number of blocks
I don't know if this information is important but here is the loading, loop and reset( It's a little ugly I'm afraid, I'm a Delphi programmer natively ). You'll notice I'm also using a font. The documentation doesn't state which pool this uses, if any?. For the purposes of this I'm just focusing on the texture. Once that is working I can delve in to the font if it doesn't use managed.
void CreateDebugDisplay() { std::cout << " " << std::endl; std::cout << "FPS Display Enabled." << std::endl; HRESULT Err; if(SUCCEEDED(Err = D3DXCreateFont(D3DDev, 18, 0, FW_BOLD, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Consolas", &Font))) { if(SUCCEEDED(Err = D3DXCreateSprite(D3DDev, &BackSprite))) { if(SUCCEEDED(Err = D3DXCreateTextureFromFile(D3DDev, "..\\media\\non\\back.dds", &BackTex))) { std::cout << " " << std::endl; std::cout << "FPS Display Loaded." << std::endl; } else { std::cout << " " << std::endl; std::cout << "FPS Texture Failure." << std::endl; std::cout << DXGetErrorString9(Err) << std::endl; std::cout << "Error ( " << DXGetErrorDescription9(Err) << " )" << std::endl; std::cout << "This error is non-terminal. FPS Display Disabled." << std::endl; std::cout << " " << std::endl; DoDisplay = false; } } else { std::cout << " " << std::endl; std::cout << "FPS Display Sprite Failure." << std::endl; std::cout << DXGetErrorString9(Err) << std::endl; std::cout << "Error ( " << DXGetErrorDescription9(Err) << " )" << std::endl; std::cout << "This error is non-terminal. FPS Display Disabled." << std::endl; std::cout << " " << std::endl; DoDisplay = false; } } else { std::cout << " " << std::endl; std::cout << "FPS Display Font Failure." << std::endl; std::cout << DXGetErrorString9(Err) << std::endl; std::cout << "Error ( " << DXGetErrorDescription9(Err) << " )" << std::endl; std::cout << "This error is non-terminal. FPS Display Disabled." << std::endl; std::cout << " " << std::endl; DoDisplay = false; } return; }
void Render() { HRESULT Err; Err = pixie->GetDevice()->TestCooperativeLevel(); if(Err == D3D_OK) { pixie->Open(); //Do map here. pixie->Close(); Update(); } else { std::cout << "Device Lost. Waiting for regain." << std::endl; if(Err == D3DERR_DEVICENOTRESET) pixie->ResetDevice(true); } }
void ResetDevice(bool ForExclusive) { ZeroMemory(&D3DPp, sizeof(D3DPp)); D3DPp.Windowed = !ForExclusive; D3DPp.SwapEffect = D3DSWAPEFFECT_DISCARD; D3DPp.BackBufferFormat = Format; D3DPp.hDeviceWindow = Handle; D3DPp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; if(!ForExclusive) { SetWindowPos(Handle, 0, (sWidth / 2) - (wWidth / 2), (sHeight / 2) - (wHeight / 2), wWidth, wHeight, NULL); D3DPp.BackBufferWidth = wWidth; D3DPp.BackBufferHeight = wHeight; sWidth = wWidth; sHeight = wHeight; } else { D3DPp.BackBufferWidth = fWidth; D3DPp.BackBufferHeight = fHeight; sWidth = fWidth; sHeight = fHeight; } D3DPp.EnableAutoDepthStencil = TRUE; D3DPp.AutoDepthStencilFormat = D3DFMT_D16; HRESULT Err; if(SUCCEEDED(Err = D3DDev->Reset(&D3DPp))) { D3DDev->SetRenderState(D3DRS_LIGHTING, true); D3DDev->SetRenderState(D3DRS_ZENABLE, true); D3DDev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50)); std::cout << " " << std::endl; std::cout << "Device Regained." << std::endl; std::cout << " " << std::endl; //CreateDebugDisplay(); } else { std::cout << " " << std::endl; std::cout << "Attempted Device Regain Failed." << std::endl; std::cout << " " << std::endl; std::cout << DXGetErrorString9(Err) << std::endl; std::cout << "Error ( " << DXGetErrorDescription9(Err) << " )" << std::endl; std::cout << " " << std::endl; } return; }
The render code is just:
void RenderDebugDisplay() { static RECT box; if(!CapFPS) { std::ostringstream FpsBuffer; FpsBuffer << (1 / FrameDelta); Fps = FpsBuffer.str()+"fps"; } D3DXVECTOR3 Centre(0.0f, 0.0f, 0.0f); D3DXVECTOR3 Pos(50.0f, 50.0f, 0.0f); D3DXVECTOR3 PosB(0.0f, 0.0f, 0.0f); SetRect(&box, 0, sHeight - 20, sWidth, sHeight); BackSprite->Begin(NULL); BackSprite->Draw(BackTex, &box, &Centre, &PosB, D3DCOLOR_ARGB(255, 255, 83, 0)); BackSprite->End(); SetRect(&box, 10, 2, sWidth, sHeight); Font->DrawTextA(NULL, Fps.c_str(), strlen(Fps.c_str()), &box, DT_LEFT | DT_TOP, D3DCOLOR_ARGB(255, 225, 225, 225)); SetRect(&box, 0, 0, sWidth, 20); Font->DrawTextA(NULL, "Test Project", strlen("Test Project"), &box, DT_VCENTER | DT_CENTER, D3DCOLOR_ARGB(255, 225, 225, 225)); if(!CapFPS) { std::ostringstream TBuffer; TBuffer << PT->GetDeltaMillis(); Tick = TBuffer.str()+"tick"; } SetRect(&box, 0, 0, sWidth - 10, 20); Font->DrawTextA(NULL, Tick.c_str(), strlen(Tick.c_str()), &box, DT_RIGHT | DT_TOP, D3DCOLOR_ARGB(255, 225, 225, 225)); return; }
Sorry for all the source, but at the moment I'm not 100% sure what is relevant to the question and what isn't.
Thanks.