ogre icon indicating copy to clipboard operation
ogre copied to clipboard

Crash when moving Ogre to a second monitor: Warning: D3D9: Depth buffer could not be acquired

Open corentinjaffre opened this issue 2 years ago • 11 comments

System Information

  • Ogre Version: :grey_question: Ogre 1.13.1
  • Operating System / Platform: :grey_question: Windows
  • RenderSystem: :grey_question: DX9c EX

Detailled description

I know this is a common issue but that's really stressful for me: SHMUP Creator will be released in 3 weeks :/ When I'm moving the Ogre window to a second monitor, my application is throwing an exception in D3D9Texture::createTextureResources(IDirect3DDevice9* d3d9Device).

In the Ogre.log, I can see a few thousands Warning: D3D9: Depth buffer could not be acquired.

RenderSystem_Direct3D9_d.dll!Ogre::D3D9Texture::createTextureResources(IDirect3DDevice9 * d3d9Device=0x0000000003af07c0) Line 274 C++ RenderSystem_Direct3D9_d.dll!Ogre::D3D9Texture::notifyOnDeviceCreate(IDirect3DDevice9 * d3d9Device=0x0000000003af07c0) Line 1243 C++ RenderSystem_Direct3D9_d.dll!Ogre::D3D9ResourceManager::notifyOnDeviceCreate(IDirect3DDevice9 * d3d9Device=0x0000000003af07c0) Line 69 C++ RenderSystem_Direct3D9_d.dll!Ogre::D3D9Device::createD3D9Device() Line 776 C++ RenderSystem_Direct3D9_d.dll!Ogre::D3D9Device::acquire() Line 146 C++ RenderSystem_Direct3D9_d.dll!Ogre::D3D9DeviceManager::linkRenderWindow(Ogre::D3D9RenderWindow * renderWindow=0x000000000274c5f0) Line 137 C++ RenderSystem_Direct3D9_d.dll!Ogre::D3D9Device::validateDisplayMonitor(Ogre::D3D9RenderWindow * renderWindow=0x000000000274c5f0) Line 991 C++ RenderSystem_Direct3D9_d.dll!Ogre::D3D9Device::validate(Ogre::D3D9RenderWindow * renderWindow=0x000000000274c5f0) Line 844 C++ RenderSystem_Direct3D9_d.dll!Ogre::D3D9RenderWindow::beginUpdate() Line 821 C++ OgreMain_d.dll!Ogre::RenderTarget::updateImpl() Line 153 C++ OgreMain_d.dll!Ogre::RenderTarget::update(bool swap=true) Line 558 C++ ShmupCreator.exe!RealMain(HINSTANCE_ * hInstance=0x000000013fc90000, char * lpCmdLine=0x0000000000414707, int nCmdShow=10) Line 919 C++ ShmupCreator.exe!WinMain(HINSTANCE__ * hInstance=0x000000013fc90000, HINSTANCE__ * hPrevInstance=0x0000000000000000, char * lpCmdLine=0x0000000000414707, int nCmdShow=10) Line 1059 C++ [External Code]

Ogre.log

corentinjaffre avatar Feb 19 '22 09:02 corentinjaffre

what are your rendersystem settings for

[Direct3D9 Rendering Subsystem]
Allow DirectX9Ex=
Auto hardware buffer management=
Resource Creation Policy=
Use Multihead=

paroj avatar Feb 19 '22 17:02 paroj

also, the line numbers do not match what we got in git: https://github.com/OGRECave/ogre/blob/37a81ed700240a821f46d50295ea29d98b7ee5c5/RenderSystems/Direct3D9/src/OgreD3D9Texture.cpp#L274

paroj avatar Feb 19 '22 17:02 paroj

I create the Ogre window like this:

Ogre::String windowTitle = "SHMUP CREATOR by bulo studio - v" + mgr.versionNumber + " - February 2022 - One more month, and...";
	mgr.mSdlWindow = SDL_CreateWindow(
		windowTitle.c_str(),    // window title
		posX,               // initial x position
		posY,               // initial y position
		game.screenWidth,              // width, in pixels
		game.screenHeigth,             // height, in pixels
		SDL_WINDOW_SHOWN
		| (game.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)
		| SDL_WINDOW_RESIZABLE)
		;

	game.mSdlWindow = mgr.mSdlWindow;

	SDL_SetWindowMinimumSize(mgr.mSdlWindow, 1280, 720);

	//Get the native whnd
	SDL_SysWMinfo wmInfo;
	SDL_VERSION(&wmInfo.version);

	if (SDL_GetWindowWMInfo(mgr.mSdlWindow, &wmInfo) == SDL_FALSE)
	{
		OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR,
			"Couldn't get WM Info! (SDL2)",
			"GraphicsSystem::initialize");
	}

        Ogre::String winHandle;
	winHandle = Ogre::StringConverter::toString((uintptr_t)wmInfo.info.win.window);
	Ogre::NameValuePairList params;
	params.insert(std::make_pair("externalWindowHandle", winHandle));
	params.insert(std::make_pair("title", windowTitle));
	params.insert(std::make_pair("gamma", "false"));
	params.insert(std::make_pair("FSAA", Ogre::StringConverter::toString(FSAA)));
	params.insert(std::make_pair("vsync", Ogre::StringConverter::toString(isVsync)));
	params.insert(std::make_pair("monitorIndex", "0"));
	params.insert(std::make_pair("border", "fixed"));
	params.insert(std::make_pair("Allow DirectX9Ex", Ogre::StringConverter::toString(game.IsDX9Ex)));

	mgr.window = Ogre::Root::getSingleton().createRenderWindow(windowTitle, game.screenWidth, game.screenHeigth, false, &params);

corentinjaffre avatar Feb 19 '22 17:02 corentinjaffre

you are mixing

  • https://ogrecave.github.io/ogre/api/latest/class_ogre_1_1_root.html#a537b7d1d0937f799cfe4936f6b672620
  • https://ogrecave.github.io/ogre/api/latest/class_ogre_1_1_d3_d9_render_system.html#a1f3c8023280ce8b5915434b2e7f52d20

there. For the issue at hand, the latter is relevant.

paroj avatar Feb 19 '22 17:02 paroj

Thanks! I'm still lost about what parameters I should use for the renderSystem to make the application works with multi-screens.

I'm doing:

mgr.rsys = mgr.root->getRenderSystemByName("Direct3D9 Rendering Subsystem");
mgr.rsys->setConfigOption("Auto hardware buffer management", "1");
mgr.rsys->setConfigOption("Allow DirectX9Ex", "No");
mgr.rsys->setConfigOption("Use Multihead", "Auto");
mgr.rsys->setConfigOption("Resource Creation Policy", "Create on active device");
mgr.root->setRenderSystem(mgr.rsys);

I tried different combinations but still crashed every time.

I also tried to do mgr.rsys->setConfigOption("Allow DirectX9Ex", "Yes");, but in this case I'm loosing all MyGUI fonts (the textures are rendered ok, but no text), and I'm crashing when I do const Ogre::PixelBox& lockBox = tex->getBuffer(0, mip)->lock(imageBox, Ogre::HardwareBuffer::HBL_DISCARD);

corentinjaffre avatar Feb 19 '22 21:02 corentinjaffre

try "Resource Creation Policy" = "Create on all devices"

paroj avatar Feb 19 '22 22:02 paroj

I tried it and still crashing, but:

I had a lot of crashes related to textures not found (from old materials I forgot to delete). Is it expected that Ogre try to recreate not found textures when recreating all textures? 10:26:06: Ogre::FileNotFoundException::FileNotFoundException: Cannot locate resource menu_dummy.png in resource group Media. in ResourceGroupManager::openResource at C:\OgreSDK\Ogre3D\ogre\OgreMain\src\OgreResourceGroupManager.cpp (line 659)

I cleaned every wrong material. In the end, the culprit seems to be MyGUI crashing each time I move the window to the second monitor. When I export games from my editor, those games are not using MyGUI anymore and they work perfectly with dual monitors.

I noticed that when I'm using DirectX9EX, I'm losing all MyGUI fonts. In this case, I can move the window to the second monitor, but resize the window crash every time, even with only one monitor. If I'm not using DirectX9EX, MyGUi fonts are rendered ok, but when I move the window to the 2nd monitor they are sometimes messed up then Ogre crashes, or Ogre crashes.

What should I do to know more about the issue and help fix it? I have no errors in MyGUI or Ogre logs related to MyGUI fonts to guide me.

SC_dx9 SC_dx9ex

corentinjaffre avatar Feb 20 '22 10:02 corentinjaffre

when moving to a different screen, D3D9 does device lost/ device restored cycle. https://github.com/OGRECave/ogre/blob/91b7639ef31a8bd3977b492025cdaec644e30668/RenderSystems/Direct3D9/src/OgreD3D9Texture.cpp#L1292-L1300

My guess would be that the MyGUI Fonts are manually created but without providing a loader callback, so we cannot auto-restore them: https://github.com/OGRECave/ogre/blob/91b7639ef31a8bd3977b492025cdaec644e30668/RenderSystems/Direct3D9/src/OgreD3D9Texture.cpp#L257-L269

paroj avatar Feb 20 '22 15:02 paroj

I compiled MyGUI demos on mster, and I confirm that they crash when I move the window on my second screen (ex: Demo_PanelView.exe)

corentinjaffre avatar Feb 21 '22 17:02 corentinjaffre

for reference: resizing the SampleBrowser window works with and without D3D9Ex here. Dont have a second monitor right now to test that.

paroj avatar Feb 28 '22 12:02 paroj

I can confirm. I thought I was using D3D9Ex for some time, but I was mistaken (I wasn't using setConfigOption() )

Also, I compiled my app without MyGUI, and I can move the window to my second screen and it works perfectly. (without D3D9EX). Only crashing with MyGUI, unfortunately.

corentinjaffre avatar Feb 28 '22 15:02 corentinjaffre