I can't find the problem of a crash (no error when compiling

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
dipi
Posts: 10
Joined: Tue Feb 26, 2008 6:16 pm

I can't find the problem of a crash (no error when compiling

Post by dipi »

I have tried some examples(code snippets). If I compile it doesn't give any errors. But when I play it it crashes.

When I use the debugger from Visual C++
it returns that it's crash on

camera->setTarget(tris_node->getAbsolutePosition()+vector3df(0,120-lastMousePos.Y,0));

Code: Select all

#include "startup.h";

/* enkele variabelen */
ISoundEngine* soundengine = 0;
float char_speed=0.8;
float char_direc=0;
float mouse_sensitivity=3;
float grav_force=9;
int char_walking=0;
bool keys[irr::KEY_KEY_CODES_COUNT];
void mouse_look();
int screen_height;
int screen_width;
bool full_screen;
bool cursor_visible;
position2d<s32> mousePos;
position2d<s32> lastMousePos;
IrrlichtDevice *device;
//
/* input */
class MyEventReceiver : public IEventReceiver
{
public:
 virtual bool OnEvent(const SEvent& event) {
  if(event.EventType == irr::EET_KEY_INPUT_EVENT){
   keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
   return false;
  }
   return false;
  }
};


/* hoofdprogram */
int main(){
IrrXMLReader* xml = createIrrXMLReader("config.xml");
while(xml && xml->read())
  {
    switch(xml->getNodeType())
    {
    case EXN_ELEMENT:
		if (!strcmp("venster", xml->getNodeName())){
		 screen_height = atoi(xml->getAttributeValue("height"));
         screen_width = atoi(xml->getAttributeValue("width"));
		}
	   else
		   if (!strcmp("fullscreen", xml->getNodeName())){
        full_screen = atoi(xml->getAttributeValue("value"));
		   }
		   else
		   if (!strcmp("cursor", xml->getNodeName())){
         cursor_visible = atoi(xml->getAttributeValue("visible"));
		   }
		  
       break;
    }
  }
  delete xml;
  MyEventReceiver receiver;
IrrlichtDevice *device=createDevice(EDT_DIRECT3D9,dimension2d<s32>(screen_width,screen_height),32,full_screen,0,0,&receiver);
position2d<s32> mousePos = device->getCursorControl()->getPosition();
position2d<s32> lastMousePos = device->getCursorControl()->getPosition();

device->getCursorControl()->setVisible(cursor_visible);
device->getCursorControl()->setPosition(screen_width/2,screen_height/2);
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;
//engines opstarten en instellen
//config file inlezen

//einde inladen
//starten engines

IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
soundengine = createIrrKlangDevice();
IGUIEnvironment* guienv = device->getGUIEnvironment();
IAnimatedMesh* meshke = smgr->getMesh("dwarf.X");
IAnimatedMeshSceneNode* tris_node = smgr->addAnimatedMeshSceneNode(meshke);


ICameraSceneNode* camera=smgr->addCameraSceneNode();

camera->setParent(tris_node);
camera->setPosition(vector3df(-5.f,6.f,0.f));

while(device->run())
{

//stringw str = L"lastMousePos.Y=";
//str += lastMousePos.Y;
//device->setWindowCaption(str.c_str());

//PLACE CAMERA
camera->setTarget(tris_node->getAbsolutePosition()+vector3df(0,120-lastMousePos.Y,0));
tris_node->setRotation(vector3df(0.f, char_direc, 0.f));

//Move
if(keys[KEY_KEY_W])
{tris_node->setPosition(tris_node->getPosition()+vector3df(cos(((char_direc)*PI)/180)*char_speed,0,-sin(((char_direc)*PI)/180)*char_speed));}
if(keys[KEY_KEY_A])
{tris_node->setPosition(tris_node->getPosition()+vector3df(cos(((char_direc+270)*PI)/180)*char_speed,0,-sin(((char_direc+270)*PI)/180)*char_speed));}
if(keys[KEY_KEY_S])
{tris_node->setPosition(tris_node->getPosition()+vector3df(cos(((char_direc+180)*PI)/180)*char_speed,0,-sin(((char_direc+180)*PI)/180)*char_speed));}
if(keys[KEY_KEY_D])
{tris_node->setPosition(tris_node->getPosition()+vector3df(cos(((char_direc+90)*PI)/180)*char_speed,0,-sin(((char_direc+90)*PI)/180)*char_speed));}
//voorbeeld voor animatie van ventje
//if(char_walking==0&&(keys[KEY_KEY_W]||keys[KEY_KEY_A]||keys[KEY_KEY_S]||keys[KEY_KEY_D]))
//{tris_node->setMD2Animation(EMAT_RUN);
//char_walking=1;}
//else
//{if(!keys[KEY_KEY_W]&&!keys[KEY_KEY_A]&&!keys[KEY_KEY_S]&&!keys[KEY_KEY_D])
//{tris_node->setMD2Animation(EMAT_STAND);
//char_walking=0;}}

//Jump(TEST)
if(keys[KEY_SPACE])
{tris_node->setPosition(tris_node->getPosition()+vector3df(0,3,0));}
//Mouse Look
mouse_look();
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
soundengine->drop(); 
return 0;
}
void mouse_look()
{
    mousePos = device->getCursorControl()->getPosition();

    if(mousePos.X > lastMousePos.X)
    {char_direc+=mouse_sensitivity;}
    if(mousePos.X < lastMousePos.X)
    {char_direc-=mouse_sensitivity;}

    if(lastMousePos.X>=screen_width-1)
    {device->getCursorControl()->setPosition(2,mousePos.Y);}
    if(lastMousePos.X<=1)
    {device->getCursorControl()->setPosition(screen_width-2,mousePos.Y);}

    if(char_direc<=-360)
    {char_direc=0;}
    if(char_direc>=360)
    {char_direc=0;}

    if(lastMousePos.Y>screen_height)
    {device->getCursorControl()->setPosition(mousePos.X,screen_height);}
    if(lastMousePos.Y<0)
    {device->getCursorControl()->setPosition(mousePos.X,0);}


    lastMousePos = mousePos;
}
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

When using pointers you need to be sure that they're valid, are both those pointers (camera and tris_node) valid?
Image Image Image
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Yeah, according to your code they seem valid. But I am going to take a stab in the dark and say it is this:

Code: Select all

smgr->getMesh("dwarf.X")
Quite possibly, Irrlicht doesn't accept it? And only accepts .x lowercase, like:

Code: Select all

smgr->getMesh("dwarf.x")
As I said, I don't know, just a stab in the dark.
TheQuestion = 2B || !2B
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, that's ok on Windows systems. But using the returned pointer without checking for NULL might raise problems, e.g. if the mesh could not be loaded.
dipi
Posts: 10
Joined: Tue Feb 26, 2008 6:16 pm

Post by dipi »

there's something wrong in my code. But I will start again.

You may close this topic
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

How gracious of you! :P

We like to see solutions, as well as problems. Did any of the above help you? Are you making progress?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply