[SOLVED] [ogre 13] dx11 reusing unloaded manual textures

Problems building or running the engine, queries about how to use features etc.
Post Reply
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

[SOLVED] [ogre 13] dx11 reusing unloaded manual textures

Post by loath »

i'm having a crash when reusing a previously unloaded dx11 texture. this worked fine under dx9.

what i'm doing:
1. create a manual texture. ogre allocates an mSurfaceList based on my requested attributes (height, width, etc)
2. i happily use and then unload the texture when i don't need it. Ogre::Texture::unload() frees the mSurfaceList.
3. if i need the texture again, i pull the unloaded resource out of Ogre::TextureManager and call getBuffer()->lock () to fill in new data. since mSurfaceList is empty the program crashes.

how should i reinitialize the mSurfaceList? it looks like dx9's D3D9Texture::getBuffer() recreated the internal resources which is why i didn't see this before switching to dx11.

thanks!
Last edited by loath on Wed Sep 22, 2021 10:03 pm, edited 1 time in total.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: [ogre 13] dx11 reusing unloaded manual textures

Post by paroj »

loath wrote: Wed Sep 22, 2021 7:42 pm how should i reinitialize the mSurfaceList? it looks like dx9's D3D9Texture::getBuffer() recreated the internal resources which is why i didn't see this before switching to dx11.
this sounds more like a D3D9 bug to me. There should not be any internal resources while the texture is unloaded.

The canonical way would be to call load() and handle it in the ManualResourceLoader.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [ogre 13] dx11 reusing unloaded manual textures

Post by loath »

there isn't a public method that i see for a manual resource loader to call Ogre::Texture::createInternalResources() which is protected.

perhaps i could mark the texture as a render target:

Code: Select all

void Texture::loadImpl()
    {
        if (mUsage & TU_RENDERTARGET)
        {
            createInternalResources();
            return;
        }
 

here is what dx9 did:

Code: Select all

const HardwarePixelBufferSharedPtr& D3D9Texture::getBuffer(size_t face, size_t mipmap)
    {
        IDirect3DDevice9* d3d9Device = D3D9RenderSystem::getActiveD3D9Device();
        TextureResources* textureResources = getTextureResources(d3d9Device);
        if (textureResources == NULL || textureResources->pBaseTex == NULL)
        {
            // FIXME
            // createTextureResources(d3d9Device);
            // createTextureResources calls getBuffer again causing a stackoverflow
            // prefer an empty texture to crashing for now
            // to fix this we should probably use the notify mechanism instead of
            // recrating the texture in here..
            createInternalResourcesImpl(d3d9Device);
            textureResources = getTextureResources(d3d9Device);         
        }
        assert(textureResources != NULL);

        return Texture::getBuffer(face, mipmap);
}
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: [ogre 13] dx11 reusing unloaded manual textures

Post by paroj »

loath wrote: Wed Sep 22, 2021 9:28 pm there isn't a public method that i see for a manual resource loader to call Ogre::Texture::createInternalResources() which is protected.
that one is public for me.
edit: you can also directly call createInternalResources() instead of load()
loath wrote: Wed Sep 22, 2021 9:28 pm here is what dx9 did:
already at it:
https://github.com/OGRECave/ogre/pull/2202
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: [ogre 13] dx11 reusing unloaded manual textures

Post by loath »

sweet, you're right...

ok so if an unloaded manual texture already exists calling createInternalResources() adds the buffers back in and all is well.

thanks!
Post Reply