loadMap() gives me terrible framerate-drop. Leak?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

loadMap() gives me terrible framerate-drop. Leak?

Post by suliman »

So if i run my function below several times in a row, each time the framerate drops conciderately. Im i doing it wrong? I should not drop() things that come from an "add" function right? Like the terrain below, the old one will just be removed as I add another node "on top of it" right? Also the problem persists even if i drop it before adding a new...

Is it the textures?

Thanks for your help!
Erik

Code: Select all

void world::loadMap( char * name )
{
 
    //_______________________________________________________________________________________________________________
    // Terrain
    terrain = gfx.smgr->addTerrainSceneNode(HEIGHTMAP_SIZE==256 ?   "gfx/terrain/baseSmall.png" : "gfx/terrain/base.png",
        0,                                      // parent node
        -1,                                     // node id
        core::vector3df(0.f, 0.f, 0.f),         // position
        core::vector3df(0.f, 0.f, 0.f),         // rotation
        core::vector3df(MAP_SCALE, MAP_SCALE_VERTICAL, MAP_SCALE), // scale
        video::SColor ( 255, 255, 255, 255 ),   // vertexColor
        1,                                      // maxLOD
        scene::ETPS_17,                         // patchSize
        4                                       // smoothFactor
        );
 
    terrain->setMaterialFlag(video::EMF_LIGHTING, false);
    terrain->scaleTexture(1.0f, TERRAIN_SCALING);
 
    terrainSelector = gfx.smgr->createTerrainTriangleSelector(terrain, 0);
 
 
    terrain->setMaterialTexture(0,terrainTexture);
    terrain->setMaterialTexture(1,gfx.driver->getTexture("gfx/terrain/tex1.jpg"));
    terrain->setMaterialTexture(2,gfx.driver->getTexture("gfx/terrain/tex2_2.jpg"));
    terrain->setMaterialTexture(3,gfx.driver->getTexture("gfx/terrain/tex3.jpg"));
    terrain->setMaterialType((video::E_MATERIAL_TYPE)terrainMaterial);          
    terrain->setMaterialFlag(video::EMF_ANISOTROPIC_FILTER , true);
}
 
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: loadMap() gives me terrible framerate-drop. Leak?

Post by Foaly »

Scene nodes won't be removed, if you add a second node on top.
It's right, if you did not grab an object, you should not drop it.
A scene node stays in the scene, even if you change "your" pointer, because the scene manager keeps it's own reference to it.
To remove a scene node, simply call remove().
For example: terrain->remove();
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: loadMap() gives me terrible framerate-drop. Leak?

Post by suliman »

Yes, remove() was what i needed! No noticable lag after spamming the funcion now:)

This "drop and remove" is a bit confusing for us noobs to the engine.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: loadMap() gives me terrible framerate-drop. Leak?

Post by CuteAlien »

The grab() & drop() is about memory management. The rules there are - you call drop() when you did create an element with a function that started with the word "create" or when you did grab() it.

Stuff like remove() is about adding removing object to data structures like the scenegraph. Should have been in the SceneManager instead of the nodes as that is also where you add nodes. Maybe that would have made it less confusing. It also does internal memory management (calling grab()&drop()), but you don't have to care about that.
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