Problem with multiple source and header files

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.
NextDesign
Posts: 12
Joined: Mon Mar 20, 2006 11:10 pm
Contact:

Problem with multiple source and header files

Post by NextDesign »

Hi,

So Im working on the terrain tutorial, and I am now expanding it into a game. So I broke the camera code into another .cpp file, and included a header that has all of my includes in it. The program compiles just fine, but when I run the program, I get an unhandled exception error.

Could someone please take a look at my code? Its probably something stupidly simple.

Thanks in advance!

Project and Source code (VS .NET 2005)
cadue
Posts: 72
Joined: Mon Mar 13, 2006 8:33 pm
Location: Italy - Friuli - Monfalcone - Staranzano

Post by cadue »

you have committed a simple error here:

Code: Select all

IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600), 32, false, true, false);

	// disable mouse cursor
	device->getCursorControl()->setVisible(false);


	addUserControlledCamera();
You call the function "addUserControlledCamera()", this function use *smgr, for do this:

Code: Select all

smgr->addCameraSceneNodeFPS()
smgr are definited in the header "include.h" but not allocated whit the code:

Code: Select all

"smgr = device->getSceneManager()"
so, you have to write this:

Code: Select all

IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600), 32, false, true, false);

driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();


	// disable mouse cursor
	device->getCursorControl()->setVisible(false);
   

	addUserControlledCamera();
excuse me for my bad english and for my ignorance...but I'm 14 and i come from Italy, where the study of english is a optional (-:
NextDesign
Posts: 12
Joined: Mon Mar 20, 2006 11:10 pm
Contact:

Post by NextDesign »

Nope, that didnt work. Im still getting the exception.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

There are also tools called 'debugger' which can accomplish this task. Maybe try to learn such useful things since you won't get far without them.
and no, I did not look at your code, but you're certainly having some null pointers floating around.
stodge
Posts: 216
Joined: Fri Dec 05, 2003 5:57 pm

Post by stodge »

If you use the debugger and find out where the exception is happening, maybe a) you will see the answer yourself or b) we can help you. The debugger is a ***vital*** tool for development.
NextDesign
Posts: 12
Joined: Mon Mar 20, 2006 11:10 pm
Contact:

Post by NextDesign »

The debugger isnt working for some reason. That is why I posted here. Maybe I should have stated that earlier.
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

In my own opinion, it would be best if you started over. Create a new project and start small, for example just create the irrlicht device and have it open a window. Get that working then add a little more, this will help in debugging the code as well. :wink:
system-independent, adj.:
Works equally poorly on all systems.
-- unknown
cadue
Posts: 72
Joined: Mon Mar 13, 2006 8:33 pm
Location: Italy - Friuli - Monfalcone - Staranzano

Post by cadue »

I've used the debugger, you have the error in this line:
smgr->addCameraSceneNodeFPS();

Because smgr isn't inizialize!
excuse me for my bad english and for my ignorance...but I'm 14 and i come from Italy, where the study of english is a optional (-:
NextDesign
Posts: 12
Joined: Mon Mar 20, 2006 11:10 pm
Contact:

Post by NextDesign »

Ok, so I re-coded the program, this time just with A basic scene.

My main is as follows:
#include "include.h"

int main()
{
IrrlichtDevice *device = createDevice(EDT_SOFTWARE, dimension2d<s32>(512, 384), 16, false, false, false, 0);

IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* env = device->getGUIEnvironment();

device->setWindowCaption(L"RPG - NextDesign");

device->getCursorControl()->setVisible(false);

smgr->addCameraSceneNodeFPS(0, 100.0f, 1200.0f);

while (device->run())
{
driver->beginScene(true, true, SColor(0, 200, 200, 200));

smgr->drawAll();
env->drawAll();

driver->endScene();
}

device->drop();

return 0;
}
With the file "include.h" I declared this:
#ifndef INCLUDE_H
#define INCLUDE_H

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

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

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

#endif
Then I have the code for the terrain, which I know isn't finished yet:
#include "include.h"
#include "defines.h"

scene::ITerrainSceneNode *terrain = smgr->addTerrainSceneNode(WorldHeight);
Now, the terrain file doesn't know what device, driver, smgr, and env are. But I can't move it over to "include.h" becuase the compiler complains about them already being defined.

Does anyone know how to fix this problem?

Any help would be greatly appreciated, I'm really stuck!

-Thanks!
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

Pass the required pointers(smgr, etc) into the function that calls

Code: Select all

 scene::ITerrainSceneNode *terrain = smgr->addTerrainSceneNode(WorldHeight);
I think this should achieve what your needing (access to the scenemanager).
system-independent, adj.:
Works equally poorly on all systems.
-- unknown
NextDesign
Posts: 12
Joined: Mon Mar 20, 2006 11:10 pm
Contact:

Post by NextDesign »

How do I do that?
NextDesign
Posts: 12
Joined: Mon Mar 20, 2006 11:10 pm
Contact:

Post by NextDesign »

Anyone know? Im still stuck. Can someone help me please?
stodge
Posts: 216
Joined: Fri Dec 05, 2003 5:57 pm

Post by stodge »

Try writing a simple, stupid program with multiple header and source files that does NOT use Irrlicht. You're just geting yourself confused over something which is extremely fundamental. You need to learn this stuff.
NextDesign
Posts: 12
Joined: Mon Mar 20, 2006 11:10 pm
Contact:

Post by NextDesign »

This is the beginner forum. And as it says on the front page:
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.
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Post by cederron »

NextDesign wrote:This is the beginner forum. And as it says on the front page:
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.
Well people has answered your question but since you don't know the basics of c++ language this info is useless for you.
You should learn the very basics like writing functions with parameters, passing parameters around, pointers... all that stuff. Maybe a dedicated c/c++ forum will be better for your needs.
Post Reply