Page 1 of 1

VERY STRANGE UNKNOWN ERROR

Posted: Mon Dec 19, 2005 11:44 pm
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

Posted: Tue Dec 20, 2005 12:05 am
by Guest
please, do not do crossposting (do not post the same posts in several forum topics & threads)

bye

Posted: Tue Dec 20, 2005 12:13 am
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

Posted: Tue Dec 20, 2005 12:49 am
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:

Posted: Tue Dec 20, 2005 2:30 pm
by Guest
ok, so does anyone have any ideas?

error is in your C++

Posted: Tue Dec 20, 2005 3:49 pm
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

Posted: Tue Dec 20, 2005 3:51 pm
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

Posted: Tue Dec 20, 2005 7:17 pm
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

Posted: Tue Dec 20, 2005 7:23 pm
by Guest
1. are the textures existing?
2. do you create the class after you created the camera + scenemanager + videodriver?

bye

Posted: Tue Dec 20, 2005 7:27 pm
by bochek
yes and yes. thats whats confusing me

bochek

Posted: Tue Dec 20, 2005 8:31 pm
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

Posted: Thu Dec 22, 2005 1:52 pm
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.

your device pointer

Posted: Mon Jan 16, 2006 10:26 am
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();
...

}