[fixed] bug in CD3D9ShaderMaterialRenderer.cpp

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
runelord
Posts: 13
Joined: Sat Jan 21, 2006 10:37 am

[fixed] bug in CD3D9ShaderMaterialRenderer.cpp

Post by runelord »

I implemented a custom scene node that uses tangent space for normal or parallax mapping. It animates ocean waves after the Tessendorf paper. :)
anyway rendering worked fine..until i wanted to display the FPS via the IGUIFont::draw() method.
That made my app crash under dx9, but not under dx8 or OpenGL.

in general my code looked like this:

Code: Select all

// my custom scene node whooray
COceanSceneNode* ocean = new COceanSceneNode(smgr->getRootSceneNode(), smgr, -1, 128, scale, video::EVT_TANGENTS); 
ocean->setMaterialType(video::EMT_NORMAL_MAP_SOLID);
...set other material stuff...add light..do this and that...
gui::IGUIFont* font2 = env->getBuiltInFont();
while(device->run())
{
   driver->beginScene(paras here);		
   smgr->drawAll();
   ...
   fps = driver->getFPS(); // bla foo tralalla
   ...
  if (font2)
     font2->draw(str.c_str(),  rect<s32>(1, 1, 300, 60), video::SColor(255,255,255,255));  // CRASH! here in DX9:(
    driver->endScene();		
}



reason:
the variable OldVertexShader never got initalized.
but was being used here:

Code: Select all

void CD3D9ShaderMaterialRenderer::OnUnsetMaterial() 
{
    if (VertexShader)	
       pID3DDevice->SetVertexShader(OldVertexShader);


I probably didn't initialize my scene node correctly or maybe i have to unset the material in OnPostRender()?
anyway, it seems that its not guaranteed that OldVertexShader gets initialized, so I propose a simple fix:

initalize OldVertexShader at the CD3D9ShaderMaterialRenderer constructors to 0. :)
runelord
Posts: 13
Joined: Sat Jan 21, 2006 10:37 am

Post by runelord »

ok, i have posted a patch for that.

it also includes the ability to load an irrScene and append it to a SceneNode. Because afaik, that was not possible yet. :?:

simply use:
ISceneManager::loadScene(const c8* filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* parent=0)

u can grab the patch here if you like:
http://users.informatik.uni-halle.de/~oey/Irrlicht/

:)
Post Reply