Page 1 of 1
Runtime error at drawAll()
Posted: Fri Aug 03, 2007 12:11 pm
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:
![Confused :?](./images/smilies/icon_confused.gif)
Am I missing a file?
Posted: Fri Aug 03, 2007 12:27 pm
by hybrid
You're probably missing some media file. Check the console output which should tell you about.
Posted: Fri Aug 03, 2007 9:22 pm
by JonLT
this will also happen if you drop a child of the scene manager, without grabbing it at an earlier point.
Posted: Sat Aug 04, 2007 12:27 am
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!
Posted: Sat Aug 04, 2007 1:13 am
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
Posted: Sat Aug 04, 2007 1:39 am
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];
}
Posted: Sat Aug 04, 2007 1:56 am
by JonLT
it looks okay...
try making you device and event receiver in the main scope.
i have no clue whats wrong, sorry
Posted: Sat Aug 04, 2007 2:47 am
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.
![Embarassed :oops:](./images/smilies/icon_redface.gif)