Problems creating multiple terrains

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
Evil Mr Sock
Posts: 37
Joined: Fri Jul 02, 2004 5:36 pm
Location: Albany, NY
Contact:

Problems creating multiple terrains

Post by Evil Mr Sock »

here is my function to create terrain, it's currently nothing special (since it's not working properl)

Code: Select all

void Create_Terrain_Map (irr::scene::ISceneManager * smgr, 
                         irr::video::IVideoDriver * driver,
                         irr::scene::ITriangleSelector * selector,
                         irr::scene::IMetaTriangleSelector * metaSelector)
{
    // Create terrain from 2d image
    irr::video::IImage* heightmap;
    irr::video::IImage* texture;
    irr::scene::IAnimatedMesh* terrain; 
    irr::scene::ISceneNode* mapnode;
  
    heightmap = driver->createImageFromFile("C:\\Evil Rocket\\art\\3d\\maps\\terrain.bmp"); 
    
    texture  = driver->createImageFromFile("C:\\Evil Rocket\\art\\3d\\maps\\terrain_texture.jpg");  
      
    terrain  = smgr->addTerrainMesh ("0",texture, heightmap,irr::core::dimension2d<irr::f32>(64.0f,64.0f),256.0f );
    
    mapnode  = smgr->addMeshSceneNode(terrain->getMesh(0)); 
    
    mapnode ->setPosition(irr::core::vector3df(-400,-256,-256));
    mapnode ->setMaterialFlag(irr::video::EMF_LIGHTING, true); 
    mapnode ->setMaterialFlag(irr::video::EMF_FOG_ENABLE, false);
      
    selector = smgr->createOctTreeTriangleSelector(terrain->getMesh(0), mapnode); 
    metaSelector->addTriangleSelector(selector); 
    selector->drop();
    
    map_array [current_map] = mapnode;

    current_map++;
  
}
now, if I try to run this function more than once, to create a second terrain node in map_array, i get an access violation at

Code: Select all

 mapnode  = smgr->addMeshSceneNode(terrain->getMesh(0)); 
    
There's another access violation with the selector/metaselector business, but I'm pretty sure this they both happen for the same reason.

Can anybody tell me why this happens? I don't have any issues creating arrays of regular scene nodes, but the terrains are obviously set up a little different. Help would be appreciated.
------------------------------------------
A monkey poured coffee in my boots.
------------------------------------------
Bog_Wraith
Posts: 12
Joined: Sun Jul 11, 2004 7:55 pm
Location: Tampa
Contact:

Post by Bog_Wraith »

this line : terrain = smgr->addTerrainMesh ("0",texture, heightmap,irr::core::dimension2d<irr::f32>(64.0f,64.0f),256.0f );

you can't have two terrain meshes named "0".
Evil Mr Sock
Posts: 37
Joined: Fri Jul 02, 2004 5:36 pm
Location: Albany, NY
Contact:

Post by Evil Mr Sock »

...huh. That'll teach me to ignore my conventions, I assumed that 0 was an ignore-type of parameter.
Awesome, thanks!
------------------------------------------
A monkey poured coffee in my boots.
------------------------------------------
Post Reply