Certain Scene Nodes Not Initializing

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
Atraitus
Posts: 16
Joined: Sun Jan 02, 2011 11:44 pm

Certain Scene Nodes Not Initializing

Post by Atraitus »

So I've been sitting here puzzling for a couple of hours over this one, and numerous Google and forum searches didn't turn up a solution. I'm creating my device and other sundry things with:

Code: Select all

windowX = 1024;
windowY = 768;
device = createDevice(EDT_OPENGL,
    dimension2d<u32>(windowX, windowY), 16, false, false, false, &receiver);
smgr = device->getSceneManager();
driver = device->getVideoDriver();
These variables are initialized in a header file. Then I make a Terrain Scene Node with:
ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"heightmap.jpg",0, // parent node
-1, // node id
core::vector3df(0.f, -1200.f, 0.f),// position
core::vector3df(0.f, 0.f, 0.f), // rotation
core::vector3df(40.f, 4.4f, 40.f), // scale
video::SColor ( 255, 255, 255, 255 ), // vertexColor
5, // maxLOD
scene::ETPS_17, // patchSize
4 // smoothFactor
);
Pretty much verbatim from the Terrain tutorial, but this is where the issue starts. This doesn't seem to actually make a Terrain Scene Node called terrain, because next I do:

Code: Select all

terrain->setMaterialFlag(video::EMF_LIGHTING, false);
This immediately results in a segfault, which is avoided with an if (terrain) check. If I comment the setMaterialFlag line, it simply segfaults when I try to set the texture, telling me there's an issue with the terrain node.

It happily performs addSkyBoxSceneNode and adding a camera a bit later if I comment out the terrain, but then it does the same thing with an Animated Mesh Scene Node I have after that.

Anyone have any idea why these nodes apparently don't exist? I'm currently on Win7 compiling with the MinGW implementation of GCC, if that makes a difference.
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Check that the terrain is really created.

-Make sure the file "heightmap.jpg" is accesible from where your program is, it should be in the same folder if you don't specify any other path to it.

-Check also that the ITerrainSceneNode *terrain pointer is valid before you operate with it, something like

Code: Select all

if(terrain){
...
}
If the engine can't load the heightmap, it will pop a small message on the console window. Check it also, Without the heightmap it is imposible to create a heightfield.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Atraitus
Posts: 16
Joined: Sun Jan 02, 2011 11:44 pm

Post by Atraitus »

The console window is stating: "Generated terrain data (512x512) in 0.3120 seconds", so I think it's really creating the terrain and reading the heightmap (which is in the same folder as the executable).

If after I declare the pointer I immediately do an

Code: Select all

if (terrain)
check, it returns false, even though I had just declared and set the pointer the line before.
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Is also 0 the parent node of the example where you are copying from? Try to set the parent node to "smgr->getRootSceneNode();"

But from what you tell, the problem may be that even if the code is run, and all, the terrain isn't actually returned. Could you post the output of the console?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Atraitus
Posts: 16
Joined: Sun Jan 02, 2011 11:44 pm

Post by Atraitus »

Yes, I didn't change the parent node when I copied it. I set it to the Root scene node just now, and there was no change. The output of the console window isn't very helpful (at least to me), but here it is:

Code: Select all

Irrlicht Engine version 1.7.2
Microsoft Windows 7 Professional Edition (Build 7600)
Using renderer: OpenGL 3.3.0
GeForce 9500 GT/PCI/SSE2: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
GLSL version: 3.3
Loaded mesh: placeholder.3ds
Generated terrain data (512x512) in 0.3710 seconds
Loaded texture: *snip*/terrtex.jpg
Loaded texture: *snip*/sand_grey.png
Loaded texture: *snip*/sky.jpg
Resizing window (1024 768)
At this point it segfaults, according to the debugger it segfaults when I try to access the terrain pointer.

It seems like you're correct in saying that the terrain isn't returned, but I have no idea what to do about it at this point.


EDIT: Looking at the console now I'm noticing that it loads the textures into memory, which is using the terrain pointer:

Code: Select all

terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0,
             driver->getTexture("terrtex.jpg"));
terrain->setMaterialTexture(1,
             driver->getTexture("sand_grey.png"));
terrain->setMaterialType(video::EMT_DETAIL_MAP);
terrain->scaleTexture(1.0f, 200.0f);
Now I'm totally confused.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

Do you use the irrlicht library provided by the SDK, or are you using your own compile?

A lot of segfaults occur because of incorrect library linking or by using a dynamic library which doesn't match the version of the needed library
I don't see anything wrong with your code, so maybe this could be an issue
Atraitus
Posts: 16
Joined: Sun Jan 02, 2011 11:44 pm

Post by Atraitus »

I'm using the version provided with the SDK. I haven't gotten around to tinkering with my own compile yet (honestly, I haven't needed to modify anything in it yet).
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

I can't really point to any reason why the heightfield isn't geneated, or why is it failing.

Try the Burnings Video renderer. It is a software renderer, if it works, the problem maybe within the OpenGL driver
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Atraitus
Posts: 16
Joined: Sun Jan 02, 2011 11:44 pm

Post by Atraitus »

Nope, even with the Burnings Video renderer it produced the same segfault. I really don't know what to do from here...
KP84
Posts: 44
Joined: Thu Feb 24, 2011 5:08 am

Post by KP84 »

Just thinking out loud here.

try different image formats (thought it should be a bmp but propably I am wrong here 8) )

for dianostics you could try this

Code: Select all

ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( "novalidpath", ..., bool addAlsoIfHeightmapEmpty = TRUE )
Now you should be able to tell if it's the image wich could be corrupted somehow

then, to diagnose further

Code: Select all

terrain->loadHeightMap( ... ) 
OR
terrain->loadHeightMapRAW( ... ) 
also another test, create a new project to just load in the terrain.

Code: Select all

// if you think real code is always interresting, read this line again
Post Reply