OGRECave / ogre-next

aka ogre v2 - scene-oriented, flexible 3D C++ engine
https://ogrecave.github.io/ogre-next/api/latest
Other
1.08k stars 233 forks source link

Win32 Window doesn't unregister class #393

Open Hilarius86 opened 1 year ago

Hilarius86 commented 1 year ago

When creating a window for the DirectX 11 Rendersystem a WindowClass is registered. That window class is not unregistered. In 2.1 that was silently ignored and a window was created anyway, but now (2.2 for me) it fails and throws an exception.

ogre-next\RenderSystems\Direct3D11\src\Windowing\WIN32\OgreD3D11WindowHwnd.cpp

if (!mClassRegistered { if (!RegisterClassEx(&wcex)) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "RegisterClassEx failed! Cannot create window", "D3D11WindowHwnd::create"); } mClassRegistered = true; }

Shouldn't this class unregister it`s window class in the destroy function ala?

if( mClassRegistered ) { UnregisterClass( OGRE_D3D11_WIN_CLASS_NAME, 0 ); mClassRegistered = false; }

darksylinc commented 1 year ago

Hi!

The block is protected by a static global variable:

if( !mClassRegistered )
{
    mClassRegistered = true;
}

How are you able to enter that block twice?

Hilarius86 commented 1 year ago

I have to look for it a little more. Working theory is about unloading the Ogre Dlls. RenderSystems are Plugins and loaded/unloaded with the Ogre Root, which I shut down in between.

Hilarius86 commented 1 year ago

It works as described. When shutting down the 3D rendering part of the application OgreRoot is deleted. That unloads all plugins and therefore the dll. When restarting 3D, the Dll is loaded again and a new set of statics is generated / initalised. But the registration of the windowclass is still active.

Hilarius86 commented 10 months ago

@darksylinc Do you care for me to provide a PR for this? Finishing up on updateing to 2.2 and remembered this issue.

darksylinc commented 10 months ago

Sure!!!

PRs are more than welcome!