Backbuffer crashes on resize

Started by
4 comments, last by 21st Century Moose 11 years, 2 months ago

I'm trying to make the backbuffer get resized when the window gets resized.Here's the code:


case WM_SIZE:
              
              int mClientWidth  = LOWORD(lParam);
		      int mClientHeight = HIWORD(lParam);
		      
		      g_engine->setScreenHeight(mClientHeight);
		      g_engine->setScreenWidth(mClientWidth);
		     if(g_engine->p_device){
              D3DDISPLAYMODE dm;
		      g_engine->p_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);
              D3DPRESENT_PARAMETERS pa;
              
              pa.Windowed = true;
              pa.hDeviceWindow = g_engine->getWindowHandle();
              pa.SwapEffect = D3DSWAPEFFECT_DISCARD;
              pa.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
		      pa.BackBufferFormat = dm.Format;
		      pa.BackBufferCount = 1;
		      pa.MultiSampleType = D3DMULTISAMPLE_NONE;
		      pa.MultiSampleQuality = 0;
		      pa.EnableAutoDepthStencil = true;
		      pa.AutoDepthStencilFormat = D3DFMT_D16;
		      
		      pa.FullScreen_RefreshRateInHz = 0;
		     
		      pa.BackBufferWidth = mClientWidth;
		      pa.BackBufferHeight = mClientHeight;
		      g_engine->p_device->Reset(&pa);
		      
              }
		      break;
	   }

I can't understand what's wrong!

Advertisement

I think your issue is more then likely that you are not calling the OnResetDevice for your various Directx Objects.

"Before calling the IDirect3DDevice9::Reset method for a device, an application should release any explicit render targets, depth stencil surfaces, additional swap chains, state blocks, and D3DPOOL_DEFAULT resources associated with the device."

I actually call my OnResetDevice calls after I do the reset, and it doesnt seem to bother my app. However thats what the MSDN says...

Aside from what Michael already said, have you tried setting breakpoints in Visual Studio? If the above post is not the problem, try setting a breakpoint before you reset your Direct3D device and trace each step to find out where your crash occurs. Also, are you running the debug or release version of Direct3D? Try running in debug mode in Direct3D and Visual Studio, then check the debug output window for any Direct3D specific messages.

Shogun.

Damn..still doesn't work.I added this:

g_engine->getSpriteHandler()->OnResetDevice();
g_engine->p_device->Reset(&pa);
I don't understand on which objects I should call onresetdevice,i mean I don't have any other dx objects except direct input,and that one doesn't have a onreset function!

Damn..still doesn't work.I added this:


g_engine->getSpriteHandler()->OnResetDevice();

g_engine->p_device->Reset(&pa);

I don't understand on which objects I should call onresetdevice,i mean I don't have any other dx objects except direct input,and that one doesn't have a onreset function!

Anything that is created in D3DPOOL_DEFAULT needs to be reset as it is living on the GPU and isn't aware they you reset the device. This is why you mostly load textures in to D3DPOOL_MANAGED as the runtime can then reupload the image when a reset occurs.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

You need to call the objects OnLostDevice before running the Reset, then OnResetDevice after. Also Release and recreate any stateblocks you may be using, and reset all your render/texture stage/sampler states to their defaults too.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement