Howto get Scene Manager

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
MrBigBrain
Posts: 5
Joined: Fri Jul 06, 2007 10:50 pm

Howto get Scene Manager

Post by MrBigBrain »

Hello, I´ve got a problem: I have two classes(CXPong and CGame). In the CXPong class, I created a device and stored a Pointer to the Scene Manager(smgr). Now I want to use "smgr" in CGame. How can I do this? I already tried it with a Singleton, but I get an Segmentation Fault, if I try to retrieve the Scene Manager.
E.g.:
CXPong.h:

Code: Select all

class CXPong
{
 public:
       ISceneManager *smgr;
};
CXPong.cpp:

Code: Select all

CXPong::Init()
{
     device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(800, 600), 32, false, false, false, 0);
     smgr = device->getSceneManager();
}
CGame.cpp

Code: Select all

CGame::Load()
{
     // How can I get smgr, so that I can use it like this?
     smgr->getMesh("test.3DS");
}

Sorry English isnt my native Language.
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

store a pointer to the CXPong class in the CGame class
MrBigBrain
Posts: 5
Joined: Fri Jul 06, 2007 10:50 pm

Post by MrBigBrain »

Thanks for the replay. If I store a pointer to the CXPong class, there is no compiler error, but when I execute the App, there is a Runtime Error.
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

MrBigBrain wrote:Thanks for the replay. If I store a pointer to the CXPong class, there is no compiler error, but when I execute the App, there is a Runtime Error.

Code: Select all

pong->smgr->getMesh("test.3DS");
If the above crashes at runtime then something isn't set or initialized right.
Image
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

Rytz wrote:
MrBigBrain wrote:Thanks for the replay. If I store a pointer to the CXPong class, there is no compiler error, but when I execute the App, there is a Runtime Error.

Code: Select all

pong->smgr->getMesh("test.3DS");
If the above crashes at runtime then something isn't set or initialized right.
u mean

Code: Select all

CXPong->smgr->getMesh("test.3DS");
death_au
Posts: 38
Joined: Tue Apr 17, 2007 9:48 am
Location: Australia

Post by death_au »

omar shaaban wrote: u mean

Code: Select all

CXPong->smgr->getMesh("test.3DS");
No. He means:

CGame.h

Code: Select all

class CGame
{
    private:
        CXPong* pong;
}
CGame.cpp

Code: Select all

CGame::Load()
{
    pong->smgr->getMesh("test.3DS");
}
...and presumably pong->Load() is called somewhere in the CGame code beforehand
Image
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

omar shaaban wrote:u mean

Code: Select all

CXPong->smgr->getMesh("test.3DS");
No because CXPong in your original example was the name of the class as death_au pointed out :).
Image
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

mm ya but how did u know he made it like that CXPong* pong;
!!? :P
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

omar shaaban wrote:mm ya but how did u know he made it like that CXPong* pong;
!!? :P
I didn't it was just an example / guess.
Image
MrBigBrain
Posts: 5
Joined: Fri Jul 06, 2007 10:50 pm

Post by MrBigBrain »

Hmm its strange. If I put paddle = smgr->getMesh("test.3DS"); in the CXPong Class it works, but if I put it like this pong->smgr->getMesh("test.3DS"); in the CGame Class the Application crashes.
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

MrBigBrain wrote:Hmm its strange. If I put paddle = smgr->getMesh("test.3DS"); in the CXPong Class it works, but if I put it like this pong->smgr->getMesh("test.3DS"); in the CGame Class the Application crashes.
Did you create "pong" as an object pointer or just an object?

Object:

Code: Select all

CGame::Load()
{
    CXPong pong;
    pong.Init();
    pong.smgr->getMesh("test.3DS");
}

Object Pointer:

Code: Select all

CGame::Load()
{
    CXPong *pong = new CXPong;
    pong->Init();
    pong->smgr->getMesh("test.3DS");
}
Image
MrBigBrain
Posts: 5
Joined: Fri Jul 06, 2007 10:50 pm

Post by MrBigBrain »

I tried both, an Object Pointer and an Object.

edit: It´s working now :D . Unfortunately I dont know what I´ve changed.
Thanks for help.
Post Reply