[fixed]Crash in CD3D9RenderTarget::generateSurfaces()

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

[fixed]Crash in CD3D9RenderTarget::generateSurfaces()

Post 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 ...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Crash in CD3D9RenderTarget::generateSurfaces()

Post 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.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Crash in CD3D9RenderTarget::generateSurfaces()

Post 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;
}
 
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Crash in CD3D9RenderTarget::generateSurfaces()

Post by Nadro »

I fixed this bug in the latest commit. Can you confirm that all works fine on your platform too?
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Crash in CD3D9RenderTarget::generateSurfaces()

Post by CuteAlien »

Thanks, it works!
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply