Runtime error at drawAll()

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
NoodlePowa
Posts: 32
Joined: Sun Jul 15, 2007 1:02 pm
Location: California

Runtime error at drawAll()

Post by NoodlePowa »

First, I downloaded Irrlicht 1.3.1 from the downloads page on the site. Everything compiled fine and everything was smooth.

Then, I started using TortoiseSVN to keep up with updates. I tried compiling something and I got a runtime error while debugging. The line where it crashed had the code:

Code: Select all

smgr->drawAll();
:? Am I missing a file?
"Be not ashamed of mistakes and thus make them crimes."
-Confucius
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You're probably missing some media file. Check the console output which should tell you about.
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

this will also happen if you drop a child of the scene manager, without grabbing it at an earlier point.
NoodlePowa
Posts: 32
Joined: Sun Jul 15, 2007 1:02 pm
Location: California

Post by NoodlePowa »

That's strange... I can't get past that smgr->drawAll(); in the examples either!

Here's my code:

Code: Select all

#include <irrlicht.h>
#include "CEventReceiver.h"

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

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

// Create the Irrlicht device - global variable
IrrlichtDevice* device = 0;
CEventReceiver EventReceiver;

int main()
{
	// Create the Irrlicht device
	device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 16, false, true, true, &EventReceiver);
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	ISceneManager* smgr = device->getSceneManager();
	IVideoDriver* driver = device->getVideoDriver();

	// Set the window title
	device->setWindowCaption(L"Tick Tock Clock");


	// Create FPS style camera
	ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100, 100);
	camera->setPosition(vector3df(0, 0, 0));
	camera->setTarget(vector3df(0, 0, 100));


	// Use media.dat
	device->getFileSystem()->addZipFileArchive("media.dat");

	// Define textures
	ITexture* TEXWall = driver->getTexture("wall.bmp");


	// Add a cube to make it interesting... kind of
	ISceneNode* cube = smgr->addCubeSceneNode(10, 0, 0, vector3df(0, 0, 100));
	if (cube)
	{
		cube->setMaterialTexture(0, TEXWall);
		cube->setMaterialFlag(EMF_LIGHTING, false);
	}

	// Let's go!
	while (device->run())
	{
		driver->beginScene(true, true, SColor(255, 0, 0, 50));
		smgr->drawAll();
		driver->endScene();
	}

	device->drop();
	return 0;
}
I have a zip archive named media.dat in the correct directory. It contains all the media files in Irrlicht\media and my console says "Loaded texture: wall.bmp".

VC++ is giving me:

Code: Select all

First-chance exception at 0x100c09ce in Clocks.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x100c09ce in Clocks.exe: 0xC0000005: Access violation reading location 0x00000000.
At the line smgr->drawAll();


I probably made a dumb mistake somewhere, but help!
"Be not ashamed of mistakes and thus make them crimes."
-Confucius
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

are you using the global device in the eventreceiver? Pass the device to the eventreceiver if you need it there. (globals are bad)
I think the problem is in the event receiver, please post CEventReceiver.h
NoodlePowa
Posts: 32
Joined: Sun Jul 15, 2007 1:02 pm
Location: California

Post by NoodlePowa »

Here's CEventReceiver.h:

Code: Select all

#ifndef __CEVENTRECEIVER
#define __CEVENTRECEIVER

// Include headers
#include <irrlicht.h>

// Use namespaces
using namespace irr;
using namespace core;

// Event Receiver Class
class CEventReceiver : public IEventReceiver
{
   public:
      CEventReceiver();
      virtual bool OnEvent(SEvent Event);
      bool getKeyState(EKEY_CODE key);
   private:
      bool keys[KEY_KEY_CODES_COUNT];
};

#endif 
and here's CEventReceiver.cpp:

Code: Select all

// Include headers
#include <CEventReceiver.h>

// Constructor
CEventReceiver::CEventReceiver()
{
   // Set the keypress array to false
   for (s32 i = 0; i < KEY_KEY_CODES_COUNT; i++)
   {
     keys[i] = false;
   }
}

// Event handler function
bool CEventReceiver::OnEvent(SEvent Event)
{
   // If the event type is a key input event
   if (Event.EventType == EET_KEY_INPUT_EVENT)
   {
      // Set the corresponding value in the array to the state of the key
      keys[Event.KeyInput.Key] = Event.KeyInput.PressedDown;
   }

   // Return false - ensures FPS cameras will still work
   return false;
}

// Get key state
bool CEventReceiver::getKeyState(EKEY_CODE key)
{
   return keys[key];
} 
"Be not ashamed of mistakes and thus make them crimes."
-Confucius
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

it looks okay...
try making you device and event receiver in the main scope.
i have no clue whats wrong, sorry
NoodlePowa
Posts: 32
Joined: Sun Jul 15, 2007 1:02 pm
Location: California

Post by NoodlePowa »

That's strange... I copied the files from irrlicht-1.3.1.zip from the downloads page and pasted them into my svn folder for Irrlicht. Now it works.

I knew it was a dumb mistake. :oops:
"Be not ashamed of mistakes and thus make them crimes."
-Confucius
Post Reply