[fixed] Window Resize Conflict with TerrainMesh

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
CarlS
Posts: 86
Joined: Wed May 09, 2007 1:21 am
Contact:

[fixed] Window Resize Conflict with TerrainMesh

Post by CarlS »

There appears to be a bug in Irrlicht-1.5 which causes a crash when the Maximize button is pressed in a scene containing a TerrainMesh.
It does not occur when a TerrainSceneNode is used, and it is not a problem in Irrlicht-1.4.2.
I’ve tried this on 3 different PCs (using VS2005) and get the same results on each.

The crash occurs on line 2332 of cd3d9driver.cpp, in the reset function.

I came across this while upgrading the code for my 3d viewer to use Irrlicht-1.5. The code below illustrates the problem.

If there’s a change I need to make to the code to get this to work with Irrlicht-1.5, I’d like to hear about it; otherwise it looks like a bug to me.

Code: Select all

#include "C:\Program Files\irrlicht-1.5\include\irrlicht.h"
//#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "C:\\Program Files\\irrlicht-1.5\\lib\\Win32-visualstudio\\Irrlicht.lib")
//#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

int main()
{
	IrrlichtDevice *device =
#ifdef _IRR_OSX_PLATFORM_
		createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);
#else
		createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);
#endif
	if (!device)
		return 1;

	device->setWindowCaption(L"Irrlicht-1.5 TerrainMesh Test");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	device->setResizeAble(true);

	guienv->addStaticText(L"Press Maximize to see crash",
		rect<s32>(10,10,260,22), true);

	video::IImage* colorMapImage = driver->createImageFromFile("C:/Program Files/irrlicht-1.5/media/terrain-texture.jpg");
	video::IImage* heightMapImage = driver->createImageFromFile("C:/Program Files/irrlicht-1.5/media/terrain-heightmap.bmp");

	float pixelSize = 2.f;
//	scene::IAnimatedMesh* terrain = smgr->addTerrainMesh ("TestTerrainMesh", heightMapImage, heightMapImage,
	scene::IAnimatedMesh* terrain = smgr->addTerrainMesh ("TestTerrainMesh", colorMapImage, heightMapImage,
		core::dimension2d< f32 >(pixelSize, pixelSize), // size of a pixel
		50.0f); // maximum height

	colorMapImage->drop();
	heightMapImage->drop();

	ISceneNode* node = smgr->addAnimatedMeshSceneNode(terrain);

	if (node)
	{
		node->setPosition(core::vector3df(0.f,0.f,-256.f));
		node->setMaterialFlag(EMF_LIGHTING, false);
	}

	smgr->addCameraSceneNode(0, vector3df(1000,500,0), vector3df(0,0,0));

	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}

Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

yes, seems to be a bug !!! :shock:
it doesn't "crash" for me, but it hangs and gives rapitly this output to the console:
Image
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'm going to take a wild shot in the dark and say that the problem is caused by hardware mesh buffers not getting reallocated when the device needs to be reset. i.e., I believe the following call is causing the problem

Code: Select all

buffer->setHardwareMappingHint(scene::EHM_STATIC);
Could you test the following little snippet to see if it exhibits the same problem?

Code: Select all

#include <irrlicht.h>
using namespace irr;

#ifdef _IRR_WINDOWS_ 
#  pragma comment(lib, "Irrlicht.lib")
#endif 

scene::SMeshBuffer* 
createDummyMeshBuffer() 
{ 
  scene::SMeshBuffer* mb = 
    new scene::SMeshBuffer; 
  if (!mb) 
    return 0; 

  const video::SColor color(255, 255, 255, 255);

  mb->Vertices.push_back(video::S3DVertex(-100.f,   0.f, 100.f, 0.f, -1.f, 0.f, color, 0.f, 0.f));
  mb->Vertices.push_back(video::S3DVertex(   0.f, 100.f, 100.f, 0.f, -1.f, 0.f, color, .5f, 1.f));
  mb->Vertices.push_back(video::S3DVertex( 100.f,   0.f, 100.f, 0.f, -1.f, 0.f, color, 1.f, 0.f));

  mb->Indices.push_back(0);
  mb->Indices.push_back(1);
  mb->Indices.push_back(2);

  mb->BoundingBox.reset (-100.f, 0, 100.f); 
  mb->BoundingBox.addInternalPoint(100.f, 100.f, 100.f); 

  mb->setHardwareMappingHint(scene::EHM_STATIC);

  return mb; 
} 

scene::SMesh* 
createDummyMesh() 
{ 
  scene::SMeshBuffer* mb = createDummyMeshBuffer(); 
  if (!mb) 
    return 0; 

  scene::SMesh* mesh = new scene::SMesh; 
    mesh->addMeshBuffer(mb); 
  mb->drop(); 

  mesh->recalculateBoundingBox(); 

  return mesh; 
} 


int main() 
{ 
   IrrlichtDevice *device = 
      createDevice (video::EDT_DIRECT3D9);

   if (!device) 
      return 1; 

   device->setResizeAble(true); 

   video::IVideoDriver* driver = device->getVideoDriver(); 
   scene::ISceneManager* smgr = device->getSceneManager(); 

   scene::IMeshBuffer* mb = createDummyMeshBuffer();

   smgr->addCameraSceneNode(); 

   const video::SColor color(255,100,101,140);

   const video::SMaterial material;
   const core::matrix4 matrix;

   while(device->run()) 
   { 
      if (driver->beginScene(true, true, color)) {
         smgr->drawAll();

         driver->setTransform(video::ETS_WORLD, matrix);
         driver->setMaterial(material);

         driver->drawMeshBuffer(mb);

         driver->endScene(); 
      }
   } 

   device->drop(); 

   return 0; 
} 
If the code compiles (I haven't tried), I'm guessing that it will show the problem.

Travis
Last edited by vitek on Fri Dec 26, 2008 7:43 pm, edited 1 time in total.
CarlS
Posts: 86
Joined: Wed May 09, 2007 1:21 am
Contact:

Post by CarlS »

Hi Vitek

I tried compiling it, but am getting an error at line 16
error C2065: 'color' : undeclared identifier
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, move the color definition outside the main function. But I'd also assume something like that. The new reset was only tested with RTTs. But should be simple to add them in the reset sequence.
CarlS
Posts: 86
Joined: Wed May 09, 2007 1:21 am
Contact:

Post by CarlS »

Ok, that compiled. Sorry I missed that, I'm at work, in the middle of a bunch of stuff right now.

But Vitek's program ran with no errors. The maximize button is working fine and does not cause a crash or hang.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ehh, yes, it's a too small meshbuffer (hw buffers are only used with some more vertices). Try to load a terrain mesh instead of the custom node, and call setHardwareMappingHint(EHM_NONE) on the mesh before resizing. This should cure the bug. Then try again without resetting the flag and it should fail.
You could try to fix the D3D9 driver by adding a deleteAllHardwareBuffers() in the reset sequence, where all the RTTs are also released. I'll fix it next year :wink:
CarlS
Posts: 86
Joined: Wed May 09, 2007 1:21 am
Contact:

Post by CarlS »

Fix it next year? :shock: :lol:
That's a long time, but I guess patience is a virtue :mrgreen:



I set the HardwareMappingHint as you said, and that fixed the problem:

Code: Select all

	scene::IAnimatedMesh* terrain = smgr->addTerrainMesh ("TestTerrainMesh", colorMapImage, heightMapImage,
		core::dimension2d< f32 >(pixelSize, pixelSize), // size of a pixel
		50.0f); // maximum height

	terrain->setHardwareMappingHint(scene::EHM_NEVER);

	colorMapImage->drop();
	heightMapImage->drop();

	ISceneNode* node = smgr->addAnimatedMeshSceneNode(terrain);
Thanks for the help :)
--Carl
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Next years, aka, 5 days...
joshcryer
Posts: 46
Joined: Thu Sep 13, 2007 8:57 am
Contact:

Post by joshcryer »

hybrid wrote:I'll fix it next year :wink:
:lol:

That made me literally LOL. :)
Post Reply