Problem with anything involving getBlah();

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
Anteater

Problem with anything involving getBlah();

Post by Anteater »

OK, I was just having a problem with shooting, but even doing so much as using driver->getFPS(); gives me a "This program has performed an illegal operation..." error. What the heck is up with my code?
//////////INCLUDE//////////////////////////////////////////////////////////////
#include <stdio.h>
#include <irrlicht.h>
#include <windows.h>
#include <math.h>
#include <mmsystem.h>
///////NAMESPACES//////////////////////////////////////////////////////////////
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
///////////////////DEFINE INT VALUES///////////////////////////////////////////
int resxset = 1024;
int resyset = 768;
int waitshoot = 0;
int ammo = 8;
int globalswitch = 0;
int lvlstrt = 0;
int timetoloop = 0;
int todrawlogo = 0;
int shoot = 0;
int armpos = 0;
/////////SET SOME POINTERS FOR WINDOW POSITION AND DEVICE//////////////////////
IrrlichtDevice *deviceIrr = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(resxset, resyset), 32, true, true, true,0);
s32 cnt = 0;
IGUIEnvironment* guienv = deviceIrr->getGUIEnvironment();
IVideoDriver* driver = deviceIrr->getVideoDriver();
ISceneManager* smgr = deviceIrr->getSceneManager();
/////////////////EVENTS////////////////////////////////////////////////////////
class EventRGUI1 : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
switch (event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
if (id == 104)
{
if (globalswitch == 0)
{
mciSendString("stop media/mid1.mid",NULL,0,NULL);
}
}
if (id == 103)
{
if (globalswitch == 0)
{
IGUIWindow *window1 = guienv->addWindow(rect<s32>(cnt+0,cnt+0,cnt+400,cnt+400),false,L"HELP");
guienv->addStaticText(L"Eric the Anteater and the Elixer of Life\n\nThis software is based in part on the work of the Independent JPEG Group.\n\nProgrammer........Anteater\nGame Engine.......Nikolaus Gebhardt\nSpecial Thanks....Guest\nSpecial Thanks....Fraza\nSpecial Thanks....Sarin\nSpecial Thanks....The Delgine Team",rect<s32>(20,25,300,300),1,1,window1);
}
}
if (id == 102)
{
if (globalswitch == 0)
{
IGUIElement* root1 = guienv->getRootGUIElement();
IGUIElement* btd1 = root1->getElementFromId(102,true);
btd1->remove();
IGUIElement* root2 = guienv->getRootGUIElement();
IGUIElement* btd2 = root1->getElementFromId(101,true);
btd2->remove();
IGUIElement* root3 = guienv->getRootGUIElement();
IGUIElement* btd3 = root3->getElementFromId(103,true);
btd3->remove();
IGUIElement* root4 = guienv->getRootGUIElement();
IGUIElement* btd4 = root4->getElementFromId(104,true);
btd4->remove();
mciSendString("stop media/mid1.mid",NULL,0,NULL);
mciSendString("play media/mid2.mid",NULL,0,NULL);
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
globalswitch = 1;
}
}
if (id == 101)
{
if (globalswitch == 0)
{
deviceIrr->closeDevice();
return true;
}
}
break;
}
}
if (globalswitch > 0)
{
if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
if (ammo > 0)
{
if (waitshoot > 0)
{
shoot = 1;
mciSendString("play media/gun1snd.wav",NULL,0,NULL);
ammo = ammo - 1;
waitshoot = -20;
}
}
}
}
}
if (event.EventType == EET_KEY_INPUT_EVENT)
{
if (globalswitch > 0)
{
if (event.KeyInput.Key == KEY_KEY_R)
{
ammo = 0;
}
}
if (event.KeyInput.Key == KEY_ESCAPE)
{
deviceIrr->closeDevice();
return true;
}
if (event.KeyInput.Key == KEY_SPACE)
{
mciSendString("play media/taunt1snd.wav",NULL,0,NULL);
}
}
return false;
}
};
///MAIN////////////////////////////////////////////////////////////////////////
int main()
{
///////////////////////////////CONSOLE/////////////////////////////////////////
printf ("\n");
////////////////PLAY THEME/////////////////////////////////////////////////////
mciSendString("play media/mid1.mid",NULL,0,NULL);
//////SET WINDOW CAPTION///////////////////////////////////////////////////////
deviceIrr->setWindowCaption(L"");
///////////EVENT RECEIVER//////////////////////////////////////////////////////
EventRGUI1 receiver1;
deviceIrr->setEventReceiver(&receiver1);
////////////////////////LOAD TEXTURES//////////////////////////////////////////
video:: ITexture* logo1 = driver->getTexture("media/bmp1.bmp");
video:: ITexture* irrlichtlogo1 = driver->getTexture("media/bmp2.bmp");
///////////////////ADD GUI BUTTONS/////////////////////////////////////////////
guienv->addButton (rect<s32>(5,150,105,250),0,104,L"LOAD");
guienv->addButton (rect<s32>(150,5,250,105),0,101,L"QUIT");
guienv->addButton (rect<s32>(5,5,105,105),0,102,L"START");
guienv->addButton (rect<s32>(150,150,250,250),0,103,L"ABOUT");
////////////////////////////////////////GLOBAL OBJECTS ARE LOADED//////////////
scene::IAnimatedMesh* gun1mesh = smgr->getMesh("media/gun1.x");
scene::ISceneNode* gun1node = 0;
if (gun1mesh)
{
gun1node = smgr->addOctTreeSceneNode(gun1mesh->getMesh(0));
gun1node->setMaterialFlag(EMF_LIGHTING, true);
}
scene::IAnimatedMesh* hand1mesh = smgr->getMesh("media/hand1.x");
scene::ISceneNode* hand1node = 0;
if (hand1mesh)
{
hand1node = smgr->addOctTreeSceneNode(hand1mesh->getMesh(0));
hand1node->setMaterialFlag(EMF_LIGHTING, true);
}
gun1node->addChild(hand1node);
IGUIFont* font11 = deviceIrr->getGUIEnvironment()->getFont("media/font1.bmp");
IGUIFont* font12 = deviceIrr->getGUIEnvironment()->getFont("media/font2.bmp");
////////////DO EVERYTHING//////////////////////////////////////////////////////
while(deviceIrr->run())
{
driver->beginScene(true, true, SColor(0,0,0,0));
if (globalswitch > 0)
{
timetoloop = timetoloop + 1;
todrawlogo = todrawlogo + 1;
waitshoot = waitshoot + 1;
if (armpos < 0){armpos = armpos + 1;}
}
hand1node->setPosition(vector3df(0,armpos,0));
if (waitshoot < 0 && waitshoot > - 20)
{
gun1node->setRotation(vector3df(waitshoot,0,0));
gun1node->setPosition(vector3df(0,waitshoot,0));
}
if (waitshoot > 0)
{
gun1node->setRotation(vector3df(sin(waitshoot*0.01)/2,sin(waitshoot*0.01)/2,sin(waitshoot*0.01)/2));
}
if (ammo == 0)
{
ammo = 8;
waitshoot = -160;
mciSendString ("play media/reload1snd.wav", NULL, 0, NULL);
armpos = -80;
}
////////////////////////////////////DO STUFF 4 TITLE///////////////////////////
if (globalswitch == 0)
{
driver->draw2DImage(ericlogo1, core::position2d<s32>(0,0),
core::rect<s32>(0, 0, 1024, 768), 0,
video::SColor(1, 255, 255, 255), true);
driver->draw2DImage(irrlichtlogo1, core::position2d<s32>(791,0),
core::rect<s32>(0, 0, 233, 60), 0,
video::SColor(1, 255, 255, 255), true);
}
//DO STUFF FOR FIRST LEVEL/////////////////////////////////////////////////////
if (globalswitch == 1)
{
if (lvlstrt == 0)
{
deviceIrr->getCursorControl()->setVisible(false);
scene::IAnimatedMesh* level1mesh = smgr->getMesh("media/level1.x");
scene::ISceneNode* level1node = 0;
scene::ITriangleSelector* triselector1 = 0;
if (level1mesh)
{
level1node = smgr->addOctTreeSceneNode(level1mesh->getMesh(0));
level1node->setMaterialFlag(EMF_LIGHTING, true);
triselector1 = smgr->createOctTreeTriangleSelector(level1mesh->getMesh(0),level1node, 128);
level1node->setTriangleSelector(triselector1);
}
IParticleSystemSceneNode* fire1 = smgr->addParticleSystemSceneNode(false,NULL,401,vector3df(0,175,-65),vector3df(0,0,0),vector3df(0.1,0.1,0.1));
fire1->setParticleSize(dimension2d<f32>(1,1));
fire1->setMaterialFlag(EMF_LIGHTING, false);
fire1->setMaterialTexture (0,driver->getTexture("media/part/part1.bmp"));
fire1->setMaterialType (video::EMT_TRANSPARENT_ADD_COLOR);
scene::IParticleEmitter* efire1 = fire1->createPointEmitter(core::vector3df(0,-0.2,0),5,18,video::SColor(0,255,255,255),video::SColor(0,255,0,0),200,400,22);
fire1->setEmitter(efire1);
efire1->drop();
smgr->addLightSceneNode(NULL,core::vector3df(0,170,0),video::SColor(1,255,255,255),2056,301);
smgr->addLightSceneNode(NULL,core::vector3df(2500,-448,-572),video::SColor(1,255,255,255),2056,302);
scene::ICameraSceneNode* camera1 =
smgr->addCameraSceneNodeFPS();
camera1->addChild(gun1node);
scene::ISceneNodeAnimator* camanim = smgr->createCollisionResponseAnimator(
triselector1, camera1, core::vector3df(90,60,90),
core::vector3df(0,-10,0),core::vector3df(0,60,0));
camera1->addAnimator(camanim);
lvlstrt = 1;
}
}
//////////////////////////////////MUSIC AND LOGOS AND STUFF////////////////////
if (globalswitch == 1)
{
if (shoot == 1)
{
scene::IAnimatedMesh* bullet1mesh = smgr->getMesh("media/bullet1.x");
scene::ISceneNode* bullet1node = 0;
if (bullet1mesh)
{
bullet1node = smgr->addOctTreeSceneNode(bullet1mesh->getMesh(0));
bullet1node->setMaterialFlag(EMF_LIGHTING, true);
}
shoot = 0;
}
if (timetoloop == 1800)
{
mciSendString("stop media/mid2.mid",NULL,0,NULL);
mciSendString("play media/mid2.mid",NULL,0,NULL);
timetoloop = 0;
}
}
//////////////////////////////////DRAW/////////////////////////////////////////
smgr->drawAll();
guienv->drawAll();
if (globalswitch == 0)
{
font12->draw(L"Developed by Decapitation Games",rect<s32>(320,0,1024,768),SColor(0,255,0,0));
}
if (globalswitch == 1)
{
if (todrawlogo < 300)
{
font11->draw(L"SEWER CHASE ZONE || ACT 1",rect<s32>(0,0,1024,768),SColor(0,255,0,0));
}
}
driver->endScene();
}
deviceIrr->drop();
return 0;
}
///////////////////END/////////////////////////////////////////////////////////
(Basicly if I put camera1->getPosition, getFPS, or get ANYTHING at any point in my code, it locks up.)
Strings involving the name of the game have been removed.
Xilande
Posts: 3
Joined: Tue Apr 26, 2005 1:50 pm

Post by Xilande »

It isn't a problem with your code... it's a problem with your computer
Anteater

Post by Anteater »

I guess I should have been a little more clear. :oops: As of now it works fine but adding any getBlah function after (and maybe before) the while loop makes it crash. However, the collision example (that uses getFPS)
works fine on my comp.
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

Post by rincewind »

I'd suggest you move the createDevice() stuff into main()....
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

i cant read your code man, use the 'code' button on the post form next time so you retain formatting
a screen cap is worth 0x100000 DWORDS
Anteater

Whoops

Post by Anteater »

I figured out what I was doing wrong: I was getting values out of non-existant objects :oops: , So it wasn't my computer, just me making a really stupid mistake. :oops:
Post Reply