Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
corentinjaffre opened this issue Feb 19, 2022 · 11 comments

Comments

@corentinjaffre
Copy link

corentinjaffre commented Feb 19, 2022

System Information

  • Ogre Version: ❔ Ogre 1.13.1
  • Operating System / Platform: ❔ Windows
  • RenderSystem: ❔ 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

@paroj
Copy link
Member

paroj commented Feb 19, 2022

what are your rendersystem settings for

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

@paroj
Copy link
Member

paroj commented Feb 19, 2022

also, the line numbers do not match what we got in git:

@corentinjaffre
Copy link
Author

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
Copy link
Author

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);

@paroj
Copy link
Member

paroj commented Feb 19, 2022

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

@corentinjaffre
Copy link
Author

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

@paroj
Copy link
Member

paroj commented Feb 20, 2022

when moving to a different screen, D3D9 does device lost/ device restored cycle.

void D3D9Texture::notifyOnDeviceReset(IDirect3DDevice9* d3d9Device)
{
D3D9_DEVICE_ACCESS_CRITICAL_SECTION
if(mD3DPool == D3DPOOL_DEFAULT)
{
createTextureResources(d3d9Device);
}
}

My guess would be that the MyGUI Fonts are manually created but without providing a loader callback, so we cannot auto-restore them:

if (isManuallyLoaded())
{
preLoadImpl();
// create the internal resources.
createInternalResourcesImpl(d3d9Device);
// Load from manual loader
if (mLoader != NULL)
{
mLoader->loadResource(this);
}
postLoadImpl();

@corentinjaffre
Copy link
Author

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)

@paroj
Copy link
Member

paroj commented Feb 28, 2022

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

@corentinjaffre
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants