Page 1 of 1

1.11.2 Cubemap cleanup crash

Posted: Sat Nov 17, 2018 8:27 pm
by rpgplayerrobin
Ogre Version:: 1.11.2
Operating System:: Windows 10
Render System:: Direct3D11


I have an assert crash when exiting my application when using Direct3D11 with a cubemap texture (with RTT), but I think it might be a bug.

Everything works on OpenGL, Direct3D9 and Direct3D11 with the cubemap texture, but it only crashes on exit when using Direct3D11.
Normal render target textures (with only one face) works properly, it is only the 6 face render target texture of cubemaps that crashes.

I create the cubemap texture like this:

Code: Select all

TexturePtr cubemapTexture = TextureManager::getSingleton().createManual("testCubemapTexture",
That in turn goes into D3D11HardwarePixelBuffer::D3D11HardwarePixelBuffer 6 times (one per face of the cubemap):

Code: Select all

RenderTexture *trt = new D3D11RenderTexture(name, this, zoffset, mDevice);
On the "new D3D11RenderTexture", it gets added to "D3D11DeviceResourceManager::mResources", which then adds 6 RenderTextures to mResources in the end.

The thing in here is that "attachRenderTarget" only adds the RenderTexture if it has a unique name, which is true for the first time it comes into that, but for all 5 other faces nothing happens in that function because the RenderTarget name is not unique.
Is this a bug? Should it not also add "mFace" to the name in D3D11HardwarePixelBuffer::D3D11HardwarePixelBuffer?

After this is done, the texture can be rendered and everything in the application works with the cubemap.
But, when exiting the application and removing the texture, it comes into D3D11Texture::freeInternalResourcesImpl, which calls "mSurfaceList.clear()".
mSurfaceList has 6 objects in it, which is correct, and when clearing it the code jumps automatically 6 times to D3D11HardwarePixelBuffer::~D3D11HardwarePixelBuffer:

Code: Select all

	// Delete all render targets that are not yet deleted via _clearSliceRTT
	for(size_t zoffset=0; zoffset<mDepth; ++zoffset)
As you may understand here, destroyRenderTarget is called for the mSliceTRT, but as I mentioned before, that name is not unique.
This only destroys the first render target of the 6 created.

Later it comes to D3D11DeviceResourceManager::~D3D11DeviceResourceManager, which uses "assert(mResources.empty())" and crashes because there are still 5 objects in it (the last 5 of the 6 render targets to be exact).

Anyone know what is happening here?
Am I doing something wrong?
Is this a bug?

Thanks in advance! :D



Re: 1.11.2 Cubemap cleanup crash

Posted: Sun Nov 18, 2018 12:02 pm
by paroj
if you blame the "name" line you get this commit: ... 5397c763f8

so, yes this is a bug ;)

Re: 1.11.2 Cubemap cleanup crash

Posted: Sun Nov 18, 2018 6:54 pm
by rpgplayerrobin
I don't understand. :o

Is that bug solved with that commit? It seems to use the same code as my code uses:

Code: Select all

name = "rtt/"+StringConverter::toString((size_t)mParentTexture) + "/" + StringConverter::toString(mMipLevel) + "/" + parentTexture->getName();
What is the correct way to solve this bug? How do I solve it?

Re: 1.11.2 Cubemap cleanup crash

Posted: Sun Nov 18, 2018 10:31 pm
by paroj
no this is the commit that last touched the line. As you can tell from the commit message the author already expected bugs there.

this should be the fix: ... 6c6d6aebad

Re: 1.11.2 Cubemap cleanup crash

Posted: Mon Nov 19, 2018 6:33 am
by rpgplayerrobin
I was not sure if that was the way to solve it, so thank you! It works now! :D