Page 1 of 2

Problem with multiple source and header files

Posted: Tue Jul 11, 2006 11:02 pm
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)

Posted: Wed Jul 12, 2006 7:06 am
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();

Posted: Wed Jul 12, 2006 4:07 pm
by NextDesign
Nope, that didnt work. Im still getting the exception.

Posted: Wed Jul 12, 2006 9:03 pm
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.

Posted: Wed Jul 12, 2006 11:50 pm
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.

Posted: Thu Jul 13, 2006 12:25 am
by NextDesign
The debugger isnt working for some reason. That is why I posted here. Maybe I should have stated that earlier.

Posted: Thu Jul 13, 2006 4:04 am
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:

Posted: Thu Jul 13, 2006 8:44 am
by cadue
I've used the debugger, you have the error in this line:
smgr->addCameraSceneNodeFPS();

Because smgr isn't inizialize!

Posted: Fri Jul 14, 2006 11:13 pm
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!

Posted: Sat Jul 15, 2006 2:43 am
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).

Posted: Sat Jul 15, 2006 4:21 am
by NextDesign
How do I do that?

Posted: Sun Jul 23, 2006 12:33 am
by NextDesign
Anyone know? Im still stuck. Can someone help me please?

Posted: Sun Jul 23, 2006 12:40 am
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.

Posted: Sun Jul 23, 2006 1:12 am
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.

Posted: Sun Jul 23, 2006 1:22 am
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.