[SOLVED] Issue with getSceneManager()

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
CasualYouTuber31
Posts: 3
Joined: Sat May 04, 2019 1:04 am

[SOLVED] Issue with getSceneManager()

Post by CasualYouTuber31 »

Hi all, I have recently been on the lookout for a 3D rendering engine and have found Irrlicht. It's appealing to me and I'm trying it out to see if it suits my needs. Accordingly, I've started my journey with the first tutorial (http://irrlicht.sourceforge.net/docu/example001.html).
I've followed the tutorial and understood everything successfully.
However, when I compiled the complete code and executed it, it crashed after the program created the Irrlicht device.
Using a debugger, I was able to identify that a segmentation fault occurred on this line of code:

Code: Select all

IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
And using the watch list I noticed something funny about the addresses stored in the smgr and mesh pointers:

Code: Select all

Locals   Values
device   0x29f3a08
driver   0x29f5978
smgr     0xf32a288
guienv   0x29f76d0
mesh     0x754f6bba <onexit+58>
node     0xfffffffe
(The node pointer is as such because it hasn't been defined yet, but I suppose y'all would know that).
(This is just a specific example: debugging multiple times results in different addresses but the same 'effect' of the smgr appearing 'out of sync' still occurs).
From this, I'm quite certain that the address stored in smgr doesn't actually point to the scene manager. I'm guessing that there is something wrong with this line of code, where I attempt to retrieve the address pointing to the scene manager, but I have no clue why it is acting inconsistently.

Code: Select all

IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager(); //<- this line
IGUIEnvironment* guienv = device->getGUIEnvironment();
I know for a fact that the other two calls work correctly because I removed the mesh and scene manager components from the program and it executes as expected (without the mesh parts ofc) with no adverse side effects.
I have searched the forum but I haven't found anything that solved this specific problem.
Here is the full code which I typed up, in Code::Blocks, following the tutorial:

Code: Select all

#include "include/irrlicht.h"
#include <iostream>
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace std;
 
int main() {
 
    IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(640, 480), 16, false, false, false, 0);
 
    if (!device) {return 1;}
 
    device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
 
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
 
    guienv->addStaticText(L"Hello World! This is the Irrlicht engine demo!", rect<s32>(10, 10, 260, 22), true);
 
    IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
    if (!mesh) {
        device->drop();
        return 1;
    }
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
 
    if (node) {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(EMAT_STAND);
        node->setMaterialTexture(0, driver->getTexture("sydney.bmp"));
    }
 
    smgr->addCameraSceneNode(0, vector3df(0, 30, -40), vector3df(0, 5, 0));
 
    while (device->run()) {
        driver->beginScene(true, true, SColor(255, 100, 101, 140));
        smgr->drawAll();
        guienv->drawAll();
        driver->endScene();
    }
 
    device->drop();
 
    return 0;
}
My questions
1. Why is the getSceneManager() method returning what appears to be a faulty address?
2. What exactly does the <onexit+58> portion of the mesh pointer's address mean?
3. Is the 'faulty' scene manager address the root cause of the segmentation fault, or is it something else entirely?
Thanks for your time :D
Last edited by CasualYouTuber31 on Sun May 05, 2019 10:58 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Issue with getSceneManager()

Post by CuteAlien »

Sounds like some problem with the setup. Which Irrlicht version are you using, Irrlicht 1.8 from downloads? Which OS? And which IDE (like visualstudio or codeblocks)?

I think I've seen pretty much the same error once before with someone using code::blocks on Windows. Reason back then was that mingw had some compatibility troubles with older dll's and the solution was recompiling Irrlicht.

Note - you can start with using examples in the examples folder of Irrlicht. So you don't have to setup your project files for 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
CasualYouTuber31
Posts: 3
Joined: Sat May 04, 2019 1:04 am

Re: Issue with getSceneManager()

Post by CasualYouTuber31 »

Hi CuteAlien, I am indeed using Irrlicht 1.8, 1.8.4 from the downloads page. I am using Code::Blocks on Windows 10.
I have taken a look at the examples but also wanted to have a go at programming with the library, even if it's just retyping the code I found on the tutorial pages :P.
Thanks for the suggestion, I'll give recompiling the engine a shot.
I've just noticed something that correlates to what you're suggesting, I am currently using the Win32-VisualStudio DLL since I didn't find any DLL in the Win32-gcc folder. I read the readme in the gcc folder just now, however, and it gives instructions on how to compile the engine for GCC. I think made an error there :oops:.
I'll try this solution and will post the results.
CasualYouTuber31
Posts: 3
Joined: Sat May 04, 2019 1:04 am

Re: Issue with getSceneManager()

Post by CasualYouTuber31 »

Aaaaaaand, it works :D! Gosh darn it, I should have looked into it more. Thanks for the help!
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [SOLVED] Issue with getSceneManager()

Post by CuteAlien »

The project-file for c::b in example can btw also recompile the engine (+ all examples).
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