VERY STRANGE UNKNOWN ERROR

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
bochek
Posts: 12
Joined: Mon Dec 19, 2005 7:20 pm

VERY STRANGE UNKNOWN ERROR

Post by bochek »

THIS IS WEIRD!!!

dont know why its doing this but when i try to make a triangle selector the program generates a microsoft error report and closes.

i have debugged the program down to the line of code that is generating the error.

mapSelector = smgr->createTerrainTriangleSelector(terrain, 0);

mapSelector is a pointer in the private: area of a class called game, the code is part of the same class. so there should be no access problems, and it seems to work with all of the other pointers i have.

my code is as followes

Code: Select all

#include <irrlicht.h>
#include <iostream>
using namespace irr;

#pragma comment(lib, "Irrlicht.lib")

class game
{
      public:
             void setup()
             {
                  device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600),32,false);
                  printf("DONE!");
                  smgr = device->getSceneManager();
                  driver = device->getVideoDriver();
                  env = device->getGUIEnvironment();
             }
             void addCamera()
             {
                //initate the key map	
                SKeyMap keyMap[8];
                
                //fill the key map
                keyMap[0].Action = EKA_MOVE_FORWARD;
                keyMap[0].KeyCode = KEY_UP;
                keyMap[1].Action = EKA_MOVE_FORWARD;
                keyMap[1].KeyCode = KEY_KEY_W;
                            
                keyMap[2].Action = EKA_MOVE_BACKWARD;
                keyMap[2].KeyCode = KEY_DOWN;
                keyMap[3].Action = EKA_MOVE_BACKWARD;
                keyMap[3].KeyCode = KEY_KEY_S;
                            
                keyMap[4].Action = EKA_STRAFE_LEFT;
                keyMap[4].KeyCode = KEY_LEFT;
                keyMap[5].Action = EKA_STRAFE_LEFT;
                keyMap[5].KeyCode = KEY_KEY_A;
                            
                keyMap[6].Action = EKA_STRAFE_RIGHT;
                keyMap[6].KeyCode = KEY_RIGHT;
                keyMap[7].Action = EKA_STRAFE_RIGHT;
                keyMap[7].KeyCode = KEY_KEY_D;
                
                camera = smgr->addCameraSceneNodeFPS(0, 100, 500, -1, keyMap, 8);
               	camera->setPosition(core::vector3df(1900*2,300*2,3700*2));
            	camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
            	camera->setFarValue(12000.0f);
             }
             
             void hideCursor()
             {
                  device->getCursorControl()->setVisible(false);
             }
             
             void addTerain()
             {
                scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( "media/moonmap2.bmp");
                terrain->setScale(core::vector3df(60, 5, 60));
                terrain->setMaterialFlag(video::EMF_LIGHTING, true);
                terrain->setMaterialTexture(0, driver->getTexture("media/moontexture.jpg"));
                terrain->setMaterialTexture(1, driver->getTexture("media/detailmap3.jpg"));

              }
              
              void addTerrinTriangleSelector()
              {
                mapSelector = smgr->createTerrainTriangleSelector(terrain, 0);
                terrain->setTriangleSelector(mapSelector);
                mapSelector->drop();
                
                scene::ISceneNodeAnimator* anim2 = smgr->createCollisionResponseAnimator(
                mapSelector, camera, core::vector3df(60,100,60),
                core::vector3df(0,-1,0), 
                core::vector3df(0,50,0));
                camera->addAnimator(anim2);
              }
              
              void addCameraCollision()
              {
 
              }
              
              void run()
              {
                int lastFPS =-1;
            	while(device->run())
            	if (device->isWindowActive())
            	{
            		driver->beginScene(true, true, 0 );
            
            		smgr->drawAll();
            		env->drawAll();
            
            		driver->endScene();
            
            
            		int fps = driver->getFPS();
            		if (lastFPS != fps)
            		{
            			core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
            			str += driver->getName();
            			str += "] FPS:";
            			str += fps;
            
            			device->setWindowCaption(str.c_str());
            			lastFPS = fps;
            		}
            	}
            
            	device->drop();
             }
      private:
              
                IrrlichtDevice* device;
                scene::ISceneManager* smgr;
            	video::IVideoDriver* driver;
            	gui::IGUIEnvironment* env;
            	scene::ICameraSceneNode* camera;
            	scene::ITerrainSceneNode* terrain;
	protected:
            	scene::ITriangleSelector* mapSelector;
};

int main()
{
    game Game;
    Game.setup();
    Game.addCamera();
    Game.hideCursor();
    Game.addTerain();
    Game.addTerrinTriangleSelector();
    Game.addCameraCollision();
    Game.run();
    system("PAUSE");
    return 0;
}

dont know why this is happening, any help would be appreciated.

Bochek
Guest

Post by Guest »

please, do not do crossposting (do not post the same posts in several forum topics & threads)

bye
bochek
Posts: 12
Joined: Mon Dec 19, 2005 7:20 pm

Post by bochek »

wasn't getting any help over there unfortunatly so i decided to try toe advanced help as i though it might be out of the knowledge level of some of the people in the beginner help forum..

Bochek
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

Post by Conquistador »

Most of the people who help out in the advanced help also help out in the beginners forum, just remember this for next time. :wink:
Royal Hamilton Light Infantry - http://www.rhli.ca
Paris/Port Dover Pipes'n Drums - http://www.parisdover.ca
Guest

Post by Guest »

ok, so does anyone have any ideas?
Alex001
Posts: 25
Joined: Tue Dec 02, 2003 8:20 pm
Location: Germany, Munich

error is in your C++

Post by Alex001 »

you have declared terrain 2 times - as class member and local and your class member is never set:
just remove "scene::ITerrainSceneNode*" in line 57
Any fool can make things bigger, more complex, and more violent. It takes a touch of genius-and a lot of courage-to move in the opposite direction.
(Albert Einstein)
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

Strange crashes are usually caused by using a variable that isn't initialized. In your case it is 'terrain'.
You have a global and a local instance of this variable. The local version is here:

Code: Select all

void addTerain() 
             { 
                scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( "media/moonmap2.bmp"); 
remove the 'scene::ITerrainSceneNode*' and it should work.

I agree that this is a subject for the beginners help section as it is a C++ question

Good luck
bochek
Posts: 12
Joined: Mon Dec 19, 2005 7:20 pm

Post by bochek »

thanks for you help on that one!

but its happening again on another part of my code, and i cant find the same problem somewhere else.

the code is:

Code: Select all

class me : public game
{
      public:
             void addFpsWeapon()
             {
                weapon = smgr->getMesh("media/w_chaingun.md2");
                MyGun = smgr->addAnimatedMeshSceneNode( weapon );
                
                MyGun->setParent(camera);
                MyGun->setPosition(core::vector3df(0,-20,-6));
                
                MyGun->setFrameLoop(370,373);
                MyGun->setRotation(core::vector3df(0,-90,0));
                MyGun->setAnimationSpeed(30);
                MyGun->setMaterialFlag(video::EMF_LIGHTING, false);
                MyGun->setMaterialTexture(0, driver->getTexture("media/w_chaingun.pcx"));
             }
               	        
     private:
                scene::IAnimatedMeshSceneNode* MyGun;
                scene::IAnimatedMesh* weapon; 

              
};
again its crashing at the begining of the addFpsWeapon class

Bochek
Guest

Post by Guest »

1. are the textures existing?
2. do you create the class after you created the camera + scenemanager + videodriver?

bye
bochek
Posts: 12
Joined: Mon Dec 19, 2005 7:20 pm

Post by bochek »

yes and yes. thats whats confusing me

bochek
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

I would recommend doing something like this:

Code: Select all

class me : public game
{
      public:
             void addFpsWeapon()
             {
                if (smgr) weapon = smgr->getMesh("media/w_chaingun.md2");
                if (weapon) MyGun = smgr->addAnimatedMeshSceneNode( weapon );
                if (MyGun)
                {
                if (camera) MyGun->setParent(camera);
                MyGun->setPosition(core::vector3df(0,-20,-6));
                
                MyGun->setFrameLoop(370,373);
                MyGun->setRotation(core::vector3df(0,-90,0));
                MyGun->setAnimationSpeed(30);
                MyGun->setMaterialFlag(video::EMF_LIGHTING, false);
                MyGun->setMaterialTexture(0, driver->getTexture("media/w_chaingun.pcx"));
                }
             }
               	        
     private:
                scene::IAnimatedMeshSceneNode* MyGun;
                scene::IAnimatedMesh* weapon; 

              
};
This way your program will not crash. Also the weapon-mesh will not load first time. Likely there is something wrong with the (location of the) .md2 file or one of the things GFXstyLER mentioned
bochek
Posts: 12
Joined: Mon Dec 19, 2005 7:20 pm

Post by bochek »

I allmost hate to say it, but it STILL crashes even after that, weird eh?

im going to post all my code. see if anyone has any clue why this is happening.

Code: Select all


#include <irrlicht.h>
#include <iostream>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")








class game
{
      public:
             void setup()
             {
                  device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600),32,false);
                  printf("DONE!");
                  smgr = device->getSceneManager();
                  driver = device->getVideoDriver();
                  env = device->getGUIEnvironment();
             }
             void addCamera()
             {
                //initate the key map	
                SKeyMap keyMap[8];
                
                //fill the key map
                keyMap[0].Action = EKA_MOVE_FORWARD;
                keyMap[0].KeyCode = KEY_UP;
                keyMap[1].Action = EKA_MOVE_FORWARD;
                keyMap[1].KeyCode = KEY_KEY_W;
                            
                keyMap[2].Action = EKA_MOVE_BACKWARD;
                keyMap[2].KeyCode = KEY_DOWN;
                keyMap[3].Action = EKA_MOVE_BACKWARD;
                keyMap[3].KeyCode = KEY_KEY_S;
                            
                keyMap[4].Action = EKA_STRAFE_LEFT;
                keyMap[4].KeyCode = KEY_LEFT;
                keyMap[5].Action = EKA_STRAFE_LEFT;
                keyMap[5].KeyCode = KEY_KEY_A;
                            
                keyMap[6].Action = EKA_STRAFE_RIGHT;
                keyMap[6].KeyCode = KEY_RIGHT;
                keyMap[7].Action = EKA_STRAFE_RIGHT;
                keyMap[7].KeyCode = KEY_KEY_D;
                
                camera = smgr->addCameraSceneNodeFPS(0, 100, 800, -1, keyMap, 8);
               	camera->setPosition(core::vector3df(1900*2,300*2,3700*2));
            	camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
            	camera->setFarValue(12000.0f);
             }
             
             void hideCursor()
             {
                  device->getCursorControl()->setVisible(false);
             }
             
             void addTerain()
             {
                terrain = smgr->addTerrainSceneNode( "media/moonmap2.bmp");
                terrain->setScale(core::vector3df(60, 5, 60));
                terrain->setMaterialFlag(video::EMF_LIGHTING, true);
                terrain->setMaterialTexture(0, driver->getTexture("media/moontexture.jpg"));
                terrain->setMaterialTexture(1, driver->getTexture("media/detailmap3.jpg"));
                //	terrain->setMaterialType(video::EMT_DETAIL_MAP);
//                	terrain->scaleTexture(1.0f, 20.0f);
              }
              
              void makeTerrinTriangleSelector()
              {
                mapSelector = smgr->createTerrainTriangleSelector(terrain, 0);
                terrain->setTriangleSelector(mapSelector);
                mapSelector->drop();
                
                anim2 = smgr->createCollisionResponseAnimator(
                mapSelector, camera, core::vector3df(60,100,60),
                core::vector3df(0,-1,0), 
                core::vector3df(0,50,0));
                camera->addAnimator(anim2);
              }
              
              void addBackDrop()
              {
                smgr->addSkyBoxSceneNode(
                driver->getTexture("media/moon_up.jpg"),
                driver->getTexture("media/moon_dn.jpg"),
                driver->getTexture("media/moon_lf.jpg"),
                driver->getTexture("media/moon_rt.jpg"),
                driver->getTexture("media/moon_ft.jpg"),
                driver->getTexture("media/moon_bk.jpg"));
                driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
              }
              
              void run()
              {
                int lastFPS =-1;
            	while(device->run())
            	if (device->isWindowActive())
            	{
            		driver->beginScene(true, true, 0 );
            
            		smgr->drawAll();
            		env->drawAll();
            
            		driver->endScene();
            
            
            		int fps = driver->getFPS();
            		if (lastFPS != fps)
            		{
            			core::stringw str = L"FacePlant Studios [";
            			str += driver->getName();
            			str += "] FPS:";
            			str += fps;
            
            			device->setWindowCaption(str.c_str());
            			lastFPS = fps;
            		}
            	}
            
            	device->drop();
             }
             
             
             
     
     protected:
              
                IrrlichtDevice* device;
                scene::ISceneManager* smgr;
            	video::IVideoDriver* driver;
            	gui::IGUIEnvironment* env;
            	scene::ICameraSceneNode* camera;
            	scene::ITerrainSceneNode* terrain;

               	scene::ISceneNodeAnimator* anim2;
               	scene::ITriangleSelector* mapSelector;
};

class me : public game
{
      public:
             void addFpsWeapon()
             {
                smgr = device->getSceneManager();
                if (smgr)  weapon = smgr->getMesh("media/w_bfg.md2");
                if (weapon) MyGun = smgr->addAnimatedMeshSceneNode( weapon );
                if (MyGun)
                {
                if (camera) MyGun->setParent(camera);
                MyGun->setPosition(core::vector3df(0,-20,-6));
               
                MyGun->setFrameLoop(370,373);
                MyGun->setRotation(core::vector3df(0,-90,0));
                MyGun->setAnimationSpeed(30);
                MyGun->setMaterialFlag(video::EMF_LIGHTING, false);
                MyGun->setMaterialTexture(0, driver->getTexture("media/w_chaingun.pcx"));
                
                }
                
             }
                         
     private:
                scene::IAnimatedMeshSceneNode* MyGun;
                scene::IAnimatedMesh* weapon;

             
}; 
int main()
{
    game Game;
    me Me;
    Game.setup();
    Game.addCamera();
    Game.hideCursor();
    Game.addTerain();
    Game.makeTerrinTriangleSelector();
    Game.addBackDrop();
    Me.addFpsWeapon(); //crashes here, comment out to run
    Game.run();
    system("PAUSE");
    return 0;
}


bochek.
sdi2001

your device pointer

Post by sdi2001 »

check if your device pointer is already init. (in the function "addFpsWeapon")
:wink:

set the device pointer from the main
use
void addFpsWeapon(IrrlichtDevice* _device)
{
//and then use

if(!_device)
return;

smgr = _device->getSceneManager();
...

}
Post Reply