Crash on device creation

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
Lollerball

Crash on device creation

Post by Lollerball »

My project compiles OK, no errors or warnings. But when I run the program, it crashes on this line:

Code: Select all

device = createDevice ( video::EDT_OPENGL,
        core::dimension2d<s32>( 1024, 768 ), 16, false, false, this );
What could be wrong? I'm using Dev-C++ 4.9.8.0.
Overkills
Posts: 3
Joined: Tue Aug 31, 2004 4:47 pm
Location: France

Post by Overkills »

Code: Select all

 device = createDevice ( video::EDT_OPENGL,
        core::dimension2d<s32>( 1024, 768 ), 16, false, false, this );



First use an other renderer system like Direct3D8 or 9.
Or try to put the receiver to 0, if program run, create a receiver and put his reference !
All programmer need respect
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Yeah. If you use this then you need a "bool CYourClass::OnEvent" or it'll crash :).
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Lollerball

Post by Lollerball »

Thanks for the replies.

First of all, I'm using Dev-C++, and the Irrlicht library for Dev-C++ doesn't run with D3D. Second, the class that contains this command is inherited from IEventReceiver, and it overrides the OnEvent function, so 'this' should be ok.

Anything else you could think of?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

There's nothing wrong with that I can see, try posting the rest of your code and the error may be easier to spot.
Lollerball

Post by Lollerball »

Okay, I did some experiments by changing the line. Here's the whole CMenu:run function

Code: Select all

bool CMenu::run ( )
{
    printf ( "Attempting to create a device...\n");
 	device = createDevice ( video::EDT_OPENGL,
        core::dimension2d<s32>( 1024, 768 ), 16, false, true, 0 );    
    
    printf ( "Device created [SUCCESS]\n" );
    
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    gui::IGUIEnvironment* env = device->getGUIEnvironment();
    
    env->addButton ( core::rect<s32> ( 10,210, 100, 240 ), 0, 102, L"New Game" );
    env->addButton ( core::rect<s32> (10, 250, 100, 290 ), 0, 103, L"Load Game" );
    env->addButton ( core::rect<s32> (10, 300, 100, 340 ), 0, 101, L"Quit" );
    
    printf ( "Entering menu loop...\n" );
    
    while ( device->run() && driver )
    {
        if ( device->isWindowActive() )
        {
                driver->beginScene( true, true, video::SColor( 0, 122, 65, 171 ) );
                env->drawAll();
                driver->endScene();                
        }
    }   
    device->drop();
    return 0;
    
}
As you can see, I tried changing the line we're talking about. The code I originally posted outputted only:
Attempting to create device...

But this code outputs the following:
Attempting to create device...
Irrlicht Engine version 0.6
Microsoft Windows XP Professional Service Pack 1 (Build 2600)

Another change required to get more output is to turn stencilbuffer on. It seems there is something wrong with my event handler. Here's CMenu::OnEvent

Code: Select all

bool CMenu::OnEvent ( SEvent event )
{
    cnt = 0;
    if ( event.EventType == EET_GUI_EVENT )
    {
        s32 id = event.GUIEvent.Caller->getID();
        gui::IGUIEnvironment* env = device->getGUIEnvironment();
        
        switch ( event.GUIEvent.EventType )
        {
        case gui::EGET_BUTTON_CLICKED:
                if ( id == 101 )
                {
                     device->closeDevice();
                     return true;
                }
                
                if ( id == 102 )
                {
                     gui::IGUIWindow* window = env->addWindow (
                         core::rect<s32> ( 100 + cnt, 100 + cnt, 300 + cnt, 360 + cnt),
                         true, //modal
                         L"Start a new game");
                         
                     env->addStaticText ( L"Select difficulty level",
                         core::rect<s32>( 35, 35, 140, 50),
                         true, //border?
                         false, //wordwrap?
                         window);
                         
                     env->addButton ( core::rect<s32>( 35, 55, 140, 85 ),
                         window, 121,
                         L"Baby" );
                         
                     env->addButton ( core::rect<s32>( 35, 90, 140, 120 ),
                         window, 122,
                         L"Teen" );
                         
                     env->addButton ( core::rect<s32>( 35, 125, 140, 155 ),
                         window, 123,
                         L"Mature" );
                         
                     return true;
                }
                
                if ( id == 103 )
                {
                    openDialog = env->addFileOpenDialog ( L"Select save file to load",
                         true, //modal
                         0,    //parent
                         131 );
                }
                
                if ( id == 121 )
                    difficultyLevel = 1;
                if ( id == 122 )
                    difficultyLevel = 2;
                if ( id == 123 )
                    difficultyLevel = 3;
                    
                break;
        case gui::EGET_FILE_SELECTED:
                env->addMessageBox ( L"The file you selected was:",
                    openDialog->getFilename(),
                    true,
                    gui::EMBF_OK,
                    0, 221 );
                break;
        }
    }
}
Funny that all this used to work.
Lollerball

Post by Lollerball »

D'oh! I found the mistake :) It was in a completely different file. Now the program starts as it's supposed to.

But there's another problem: The buttons that are shown in the window, they don't work. I wonder what's wrong with that.
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Add a

return false;

at the end (before the last "}") :) ?
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Lollerball

Post by Lollerball »

Thank you!
Post Reply