I'm having a bit of a problem at the moment regarding irrlicht and its memory use... or probably my understanding of it. I'm using a separate Thread in an application that will summarise a simple graph using the terrain mesh and associated height maps. The code basically boils down to this: (I'm omitting some parts for legibility)
Code: Select all
irr::scene::ISceneManager* smgr;
video::IVideoDriver* driver;
bool wasPaused = true;
AnsiString apath = ExtractFilePath(Application->ExeName);
scene::ITerrainSceneNode* terrain = NULL;
Pause3D = true;
_control87( PC_64|MCW_EM, MCW_PC|MCW_EM );
irr::SIrrlichtCreationParameters param;
param.WindowId = hIrrlichtWindow;
param.DriverType = DriverType;
GlobalIrrlichtData.device = irr::createDeviceEx(param);
if (GlobalIrrlichtData.device == NULL)
{
ShowMessage("Internal error: IRR3D createDeviceEx failed");
return;
}
GlobalIrrlichtData.device->getTimer()->stop();
smgr = GlobalIrrlichtData.device->getSceneManager();
driver = GlobalIrrlichtData.device->getVideoDriver();
scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
cam->setTarget(core::vector3df(0,150,0));
scene::ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(core::vector3df(100,280,0), 500.0f, 0.0007);
cam->addAnimator(anim);
anim->drop();
cam->drop();
AnsiString fn_image_sky = apath + "sky.jpg";
if (FileExists( fn_image_sky))
{
smgr->addSkyDomeSceneNode( driver->getTexture(fn_image_sky.c_str()),
32,
32,
1.0,
1.2
);
}
reloadHeightMap:
/* generate texture for terrain, otherwise boring */
if (terrain == NULL)
{
terrain = (scene::ITerrainSceneNode*)smgr->getSceneNodeFromId (TERRAIN_NODE_MAGIC_COOKIE);
}
if (terrain == NULL)
{
terrain = smgr->addTerrainSceneNode(
(fn_heightmap).c_str(),
0, // parent node
TERRAIN_NODE_MAGIC_COOKIE, // node id
core::vector3df(-516.f, -50.f, -516.f), // position
core::vector3df(0.0f, 80.9f, 0.f), // rotation
core::vector3df(8.0f, 0.675f, 8.0f), // scale
video::SColor ( 255, 255, 255, 255 ), // vertexColor
1, // maxLOD: 5, ok 3, 0 ... Full details
scene::ETPS_17, // patchSize
0 // smoothFactor: 4 ok 2
);
}
else
{
terrain->loadHeightMap(GlobalIrrlichtData.device->getFileSystem()->createAndOpenFile((fn_heightmap).c_str()),
video::SColor ( 255, 255, 255, 255 ),
0);
}
ReloadHeightMap = false;
terrain->setMaterialTexture(0, driver->getTexture(fn_texture.c_str()));
if ((DriverType != video::EDT_OPENGL) && (DriverType != video::EDT_DIRECT3D9))
{
terrain->setMaterialTexture(1, driver->getTexture(fn_texture.c_str()));
}
terrain->setMaterialType(video::EMT_LIGHTMAP);
terrain->scaleTexture(1.0f, 1.0f /*20.0f*/);
DeleteFile(fn_texture);
DeleteFile(fn_heightmap);
while (!Terminated)
{
if (ReloadHeightMap)
{
Pause3D = true;
goto reloadHeightMap;
}
if (wasPaused != Pause3D)
{
if (wasPaused)
{
GlobalIrrlichtData.device->getTimer()->start();
}
else
{
GlobalIrrlichtData.device->getTimer()->stop();
}
wasPaused = !wasPaused;
}
GlobalIrrlichtData.device->getTimer()->tick();
driver->beginScene(true, true, video::SColor(255, 0x45,0xAB,0xDB));
smgr->drawAll();
driver->endScene();
if (Screenshot)
{
driver->writeImageToFile(driver->createScreenShot(), FileNameScreenshot.c_str());
Screenshot = false;
}
GlobalIrrlichtData.device->yield();
}
Anyone have any idea what I'm missing here?
(btw i'm using irrlicht 1.7.1, the same patches that I posted on the other subforum and compiled with borland...)
thanks in advance,
Magnus