HELP !

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
Darven
Posts: 3
Joined: Sat Sep 03, 2005 2:54 pm

HELP !

Post by Darven »


// ========================================================================================================
//
// Includedateien einbinden :

#include "Main.h"

// ========================================================================================================

// ========================================================================================================
//
// Globale Hilfsvariablen :

IrrlichtDevice *device = 0;
s32 cnt = 0;

// ========================================================================================================
//
// Eventreciever - Ereignissabfrage Funktinion :

class MyEventReceiver : public IEventReceiver
{
public:

virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();


switch (event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:

if (id == 101)
{
device->closeDevice();
return true;
}

if (id == 102)
{
return true;
}
break;

default:
break;
}
}
return false;
}
};



// ========================================================================================================
//
// Haupteinsprungpunkt des Programms :

int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
// Das Irrlicht (SOFTWARE DEVICE) wird erzeugt

IrrlichtDevice *device =
createDevice (EDT_SOFTWARE, dimension2d<s32>(640,480), 32, false, false, false, 0);

MyEventReceiver receiver;
device->setEventReceiver(&receiver);
device->setWindowCaption(TEXT ("Tertium"));

IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont("D4O.bmp");

if (font) skin->setFont(font);

env->addButton(rect<s32>(416, 424, 616, 460), 0, 101, TEXT ("Beenden"));
env->addButton(rect<s32>(416, 376, 616, 412), 0, 102, TEXT ("Optionen"));


while (device->run() && driver)
if (device->isWindowActive())
{
driver->beginScene (true, true, SColor(255, 160, 120, 80));
env->drawAll();
driver->endScene();
}

device->drop();

return (0);
}
This is my very short programm for testing the GUI. I´ve compiled it with the MS Visual Studio 2005 Express Edition, without any compiler-erroers or warnings. But every time the program crashed, when I pressed the Button (ID 101).

Error :
Unbehandelte Ausnahme bei 0x00411b91 in Irrlicht2.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x00000000.
Need help to solve this problem ! ;)
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post by andrei25ni »

if (id == 101)
{
device->closeDevice();
return true;
}
It suppose to close the program. :) Are you sure 'crashes' is the right term ?

And this looks weird :
int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
Why don't you use the layout from Irrlicht tutorials ?

And in the last line try "return 0;" .

And try : " createDevice (EDT_SOFTWARE, dimension2d<s32>(640,480), 32, false, false, false); "
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post by Ced666 »

In your main, you are declaring a local variable of device:

Code: Select all

IrrlichtDevice *device = 
createDevice (EDT_SOFTWARE, dimension2d<s32>(640,480), 32, false, false, false, 0); 
So, at this point your global variable device is still a NULL pointer. Thus, in your event receiver (outside the scope of main, so it doesn't see the local device variable) you will try to access member function of a NULL pointer -> crash.

Replace the line in the main by:

Code: Select all

device = 
createDevice (EDT_SOFTWARE, dimension2d<s32>(640,480), 32, false, false, false, 0); 
BTW: try to use your debugger also to detect errors like that, it is much more faster than posting questions in a forum :wink:
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post by Ced666 »

@andrei25ni: what is the problem with using WinMain instead of a main ?

Also, changing "return (0);" into "return 0;" won't change anything.

And finally, it is perfectly legal to use "createDevice (EDT_SOFTWARE, dimension2d<s32>(640,480), 32, false, false, false,0);" when creating your device. All the parameters have default values and there is no problem if you supply a value for them. Check out the doc to see the number of parameters.

In brief, don't force people to use your programming style :wink:
andrei25ni
Posts: 326
Joined: Wed Dec 14, 2005 10:08 pm

Post by andrei25ni »

my bad :oops:
Darven
Posts: 3
Joined: Sat Sep 03, 2005 2:54 pm

Post by Darven »

Thanks !

i´ve replaced the first device declaration to

Code: Select all

IrrlichtDevice* device =
	createDevice (EDT_SOFTWARE, dimension2d<s32>(640,480),
                32,  false, false, false, 0);
now it work´s !

btw. : I´m still a beginner in programming C++ and in the use of the MS VC++ Ide; ... so is the outputs of the Debugger sometimes less helpful. i´ve tried it, but the disassembeled code won´t help. ;)
gfxstyler
Posts: 222
Joined: Tue Apr 18, 2006 11:47 pm

Post by gfxstyler »

just a suggestion: you should probably learn c++ first :)

see ya!
TheRLG
Posts: 372
Joined: Thu Oct 07, 2004 11:20 pm

Post by TheRLG »

Haupteinsprungpunkt... thats kinda neat sounding... hahaha... google translates that as "Point of main re-entry point " ... gosh german would be crazy for me to learn. hehe
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Darven wrote:i´ve replaced the first device declaration to

Code: Select all

IrrlichtDevice* device =
	createDevice (EDT_SOFTWARE, dimension2d<s32>(640,480),
                32,  false, false, false, 0);
now it work´s !

btw. : I´m still a beginner in programming C++ and in the use of the MS VC++ Ide; ... so is the outputs of the Debugger sometimes less helpful. i´ve tried it, but the disassembeled code won´t help. ;)
If you really replaced the first declaration with this code I'm wondering how this could work. Global variables cannot be initialized by method calls.
If you debug you should compile your program in debug mode such that the actual source code can be used for debugging. You could step through your program and check which statements are executed.
Darven
Posts: 3
Joined: Sat Sep 03, 2005 2:54 pm

Post by Darven »

@gfxstyler : Learning by doing !
I´m still tiered of the good advice to learn C++; so i tried it, if it works - good, if not, i learn and try to finde the error.

@hybrid : I´ve compiled it in the debug mode and tried to find my error so.
Btw. i´m still wondering about the use of global variables in the tutorials, most of my C++ Books warning for the use of that.
But the mistake in my programm; in the global sphere, it was only a pointer to the device ( in the tutorial it was set to zero??),
in the sphere of WinMain, the device-variables filled by the createDevice-function directly. The last version of the Programm :

Code: Select all

IrrlichtDevice* device = 0;
in the global sphere, and

Code: Select all

device = createDevice(EDT_SOFTWARE, dimension2d<s32>(640,480),
                                         32, false, false, false, 0);
in the WinMain sphere.

Thanks all of you for your advices ! ;)

@RabidLockerGnome : Thats rigth, but english is also crazy for me ;)
Post Reply