Error when loading a model

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
MrShadow97m
Posts: 3
Joined: Fri Feb 22, 2013 3:06 pm

Error when loading a model

Post by MrShadow97m »

Hi I am new to this forum. I come from Polish and play guitar. Hobby programming. That's all word of introduction. aa, and my English is not too good for which I apologize. Recently, I learned to program object. I created a class Engine:

Code: Select all

 
class engine
{
protected:
    //Grafic
    IrrlichtDevice* EngineDevice;
    IVideoDriver* EngineDriver;
    ISceneManager* EngineSMGR;
    IGUIEnvironment* EngineGUI;
    E_DRIVER_TYPE driverType;
    IGUISkin* skin;
    IGUIFont* font;
    ICameraSceneNode* Camera;
 
    //Sound
    irrklang::ISoundEngine* SoundEngine;
    //Gravity
 
public:
 
 
 
};
 
and using this class to created a prototype launcher and game.everything was fine but the code started to do complicated so I created a class of "ModelManager" to keep model and load in on memory.

ModelManager.cpp

Code: Select all

#ifndef MODELMANAGER_U_INCLUDE
#define MODELMANAGER_U_INCLUDE
#include "..\headers\cModelManager.h"
 
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
 
int cModelManager::loadmodels()
{
 
   mLaserWeapon = EngineSMGR->getMesh("../media/models/lasergun/gun.md2");
 
}
#endif
 
ModelManager.h

Code: Select all

#ifndef CMODELMANAGER_U_INCLUDE
#define CMODELMANAGER_U_INCLUDE
 
 
#include "engine.h"
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
class cModelManager : engine
{
protected:
 
 
public:
    IAnimatedMesh* mLaserWeapon;
    IAnimatedMeshSceneNode* nLaserWeapon;
 
 
    int loadmodels();
 
 
 
 
};
 
 
 
 
#endif
 
and game.cpp

Code: Select all

#ifndef GAME_U_INCLUDED
#define GAME_U_INCLUDED
 
#include <iostream>
#include <conio.h>
#include <irrlicht.h>
#include "..\headers\cGame.h"
#include "..\headers\cPlayer.h"
#include "..\headers\cModelManager.h"
#include "..\headers\cMapManager.h"
 
using namespace irr;
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
 
 
 
 
int cGame::run()
{
    EngineDevice=createDevice(EDT_OPENGL,dimension2d<u32>(1024,768),16,false,false,false,0);
    EngineDriver = EngineDevice->getVideoDriver();
    EngineSMGR = EngineDevice->getSceneManager();
    EngineGUI = EngineDevice->getGUIEnvironment();
    ISceneNode* skybox=EngineSMGR->addSkyBoxSceneNode(
        EngineDriver->getTexture("../media/texture/skybox/irrlicht2_up.jpg"),
        EngineDriver->getTexture("../media/texture/skybox/irrlicht2_dn.jpg"),
        EngineDriver->getTexture("../media/texture/skybox/irrlicht2_lf.jpg"),
        EngineDriver->getTexture("../media/texture/skybox/irrlicht2_rt.jpg"),
        EngineDriver->getTexture("../media/texture/skybox/irrlicht2_ft.jpg"),
        EngineDriver->getTexture("../media/texture/skybox/irrlicht2_bk.jpg"));
cPlayer PLAYER;
cModelManager ModelMNG;
cMapManager MapMNG;
//ModelMNG.loadmodels();
PLAYER.pCamera = EngineSMGR->addCameraSceneNodeFPS();
//PLAYER.pCamera->addChild(ModelMNG.nLaserWeapon);
PLAYER.pCamera->setFarValue( 9000000 );
//MapMNG.loadmap();
loadmodel();
 
}
 
int cGame::Play()
{
 
 
 
 
 
 
 
 
 
 
EngineGUI->addImage(EngineDriver->getTexture("../media/texture/gui/celownik.png"),
            position2d<int>(512,384));
 
 
 
 
    while(EngineDevice->run())
    {
    EngineDriver->beginScene(true, true, SColor(255,100,101,140));
        //GameFps.fpsrecorder(y);
        EngineSMGR->drawAll();
        EngineGUI->drawAll();
 
 
 
        EngineDriver->endScene();
    }
 
}
 
 
#endif
 
When i add comment to code (stop function) everythink is alright but when i delete any coment of this three function //MapMNG.loadmap();
//ModelMNG.loadmodels();
//PLAYER.pCamera->addChild(ModelMNG.nLaserWeapon);

Error windows with button don't send report to microsoft windows. help pls.
//class cPlayer is like cModelManager but only with player model.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Re: Error when loading a model

Post by sudi »

...you are not initializing the pointers in your ModelMNG. You might want to pick up a book/tutorial about c++ and how to programm with it.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
MrShadow97m
Posts: 3
Joined: Fri Feb 22, 2013 3:06 pm

Re: Error when loading a model

Post by MrShadow97m »

... ok I understand. without the ability to start something but as soon as we learn in practice. I have read the section on pointers but I'm not sure how to do it. if someone could write me fixed code? please and thank.


My c++ skill is low but i still learning... my futer job i think is play guitar but i like programmin and i will still do this. I will add physic NEWTON to this project for this i optymalize code. Code of the game is more complex and it works but I try to break down the elemnty what causes errors. (due to my lack of knowledge)
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Re: Error when loading a model

Post by sudi »

like i said init the pointers with some objects. In your run method you init some pointers but you don't do it in your other classes. pointers don't magicly know what they are supposed to point to. i don't think you understood how inheritance works. in your case you are probably looking for static member vars in your engine class.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
MrShadow97m
Posts: 3
Joined: Fri Feb 22, 2013 3:06 pm

Re: Error when loading a model

Post by MrShadow97m »

ok ok i read c++ book and i understand but i found another error not in the code but in my computer.(tittle in application is "??????????????" and application crash. I think i understand what pointers work but program still don't work (can't install directx/opengl and software crash i tried example hello word but still error and ???????????????) I must format computer but Could I can please to write this one pointer on the code above? because i still don't sure if i think good...
jaworekplay
Posts: 36
Joined: Mon Jan 23, 2012 11:14 pm
Location: Lancs, UK

Re: Error when loading a model

Post by jaworekplay »

+1 Sudi.
What you need to do is to initialise the nLaserWeapon with nLaserWeapon like this

Code: Select all

nLaserWeapon = smgr->addAnimatedMeshSceneNode(mLaserWeapon);
This is explained in the Hello World tutorial.
Good Luck. :mrgreen:
Post Reply