Page 1 of 1

[fixed]Crash in CD3D9RenderTarget::generateSurfaces()

Posted: Wed Dec 09, 2015 3:02 pm
by CuteAlien
The following will crash in d3d9 (works in OpenGL) in current trunk:

Code: Select all

 
#include <irrlicht.h>
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
using namespace irr;
 
int main(int argc, char** argv)
{
    core::dimension2d<u32> dim(800,600);
    IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9, dim);
    //IrrlichtDevice *device = createDevice(video::EDT_OPENGL, dim);
    video::IVideoDriver* driver = device->getVideoDriver();
 
    irr::video::ITexture * rt = driver->addRenderTargetTexture(dim, "rt", irr::video::ECF_A8R8G8B8);
    driver->setRenderTarget(rt, irr::video::ECBF_COLOR|irr::video::ECBF_DEPTH, irr::video::SColor(0,0,0,0));
    driver->setRenderTarget((irr::video::ITexture *)nullptr, irr::video::ECBF_COLOR|irr::video::ECBF_DEPTH);
    driver->removeTexture(rt);
    driver->OnResize(dim);
 
    device->closeDevice();
    device->drop();
    return 0;
}
 
I'm not yet too familiar with this part of the engine. Rendertarget textures all become invalid in OnResize (which will reset the d3d device). So maybe has to do with the depthTexture which is automatically created in this case and is now no longer valid? But just guessing so far ...

Re: Crash in CD3D9RenderTarget::generateSurfaces()

Posted: Wed Dec 09, 2015 4:11 pm
by Nadro
Thanks for that (you're right it's probably related to invalid depth texture), I'll try to fix that until a weekend.

Re: Crash in CD3D9RenderTarget::generateSurfaces()

Posted: Sat Dec 12, 2015 3:41 pm
by CuteAlien
I played a little more around with the code. So here's an alternative program to crash it which might make it a little easier to find it (less automatic created stuff and more control over crash). Basically removeTexture can't be called before the reset for some reason. After the reset it's fine (I thought first it might simply be a missing grab(), but then that would still crash).

Code: Select all

 
#include <irrlicht.h>
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
using namespace irr;
 
int main(int argc, char** argv)
{
    core::dimension2d<u32> dim(800,600);
    IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9, dim);
    //IrrlichtDevice *device = createDevice(video::EDT_OPENGL, dim);
    video::IVideoDriver* driver = device->getVideoDriver();
 
    video::IRenderTarget* rt = driver->addRenderTarget();
    video::ITexture * rtt = driver->addRenderTargetTexture(dim, "rtt", irr::video::ECF_A8R8G8B8);
    video::ITexture* renderTargetDepth = driver->addRenderTargetTexture(dim, "DepthStencil", video::ECF_D16);
    rt->setTexture(rtt, renderTargetDepth);
    driver->setRenderTarget(rt, irr::video::ECBF_COLOR|irr::video::ECBF_DEPTH, irr::video::SColor(0,0,0,0));
    driver->setRenderTarget((irr::video::ITexture *)nullptr, irr::video::ECBF_COLOR|irr::video::ECBF_DEPTH);
//  driver->removeTexture(rtt); // crash in OnResize
//  driver->removeTexture(renderTargetDepth);   // crash in OnResize
    driver->OnResize(dim);
 
    driver->removeTexture(rtt); // OK
    driver->removeTexture(renderTargetDepth);   // OK
 
    device->closeDevice();
    device->drop();
    return 0;
}
 

Re: Crash in CD3D9RenderTarget::generateSurfaces()

Posted: Sun Jan 10, 2016 1:08 pm
by Nadro
I fixed this bug in the latest commit. Can you confirm that all works fine on your platform too?

Re: Crash in CD3D9RenderTarget::generateSurfaces()

Posted: Mon Jan 25, 2016 8:51 am
by CuteAlien
Thanks, it works!