Then I compile it, and the application opens a terminal - freezes (executing exactly 0 cycles according to process hacker) and then when killed there are two zombie processes (presumably, or whatever the equivalent is under windows) each just sitting there eating 368K of memory, they neither use CPU, GPU, net, or disk - they're just dead - they cannot be killed either, they survive end task, taskkill /F, process hacker's terminators (including the dangerous TT4 kernel mode terminator) and even a log out. The only thing that does kill them is a complete power down (they do not have parents and as such cannot be killed even by tree killing)
additionally anything trying to view their stack freezes.
anything trying to mess with its threads also freezes.
attempting to debug it just freezes gdb, nothing else happens.
Code: Select all
#include "irrlicht.h"
using namespace irr;
using namespace core;
using namespace gui;
using namespace io;
using namespace video;
using namespace scene;
bool keys[irr::KEY_KEY_CODES_COUNT];
bool mouseDownL;
bool mouseDownM;
bool mouseDownR;
f32 lastWheelMovement;
position2d<f32> cursor;
position2d<f32> cursorOld;
position2d<f32> cursorDelta;
position2d<f32> cursorDeltaOld;
f32 cameraOrbit = 45;
f32 cameraAngle = 0;
f32 cameraDistance = 30;
f32 cameraOrbitOld = 0;
f32 cameraAngleOld = 0;
f32 playerX = 0;
f32 playerY = 0;
f32 playerZ = 0;
f32 playerCompass = 30;
f32 playerTurnTo = 0;
f32 playerTurnSpeed = 1;
f32 playerMoveSpeed = 0.01f;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
// left mouse button state check
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) mouseDownL = true;
if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) mouseDownL = false;
// middle mouse button state check
if(event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN) mouseDownM = true;
if(event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP) mouseDownM = false;
if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
{
cameraDistance -= event.MouseInput.Wheel * (cameraDistance / 20) * 2;
if(cameraDistance < 10) cameraDistance = 10;
if(cameraDistance > 100) cameraDistance = 100;
}
// right mouse button state check
if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
{
mouseDownR = true;
cursorOld.X = (f32)event.MouseInput.X;
cursorOld.Y = (f32)event.MouseInput.Y;
cursorDelta.X = 0;
cursorDelta.Y = 0;
cursorDeltaOld.X = 0;
cursorDeltaOld.Y = 0;
cameraOrbitOld = cameraOrbit;
cameraAngleOld = cameraAngle;
}
if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) mouseDownR = false;
// mouse move check
if(event.MouseInput.Event == EMIE_MOUSE_MOVED)
{
// add condition that right mouse button be down
if(mouseDownR == true){
cursor.X = (f32)event.MouseInput.X;
cursor.Y = (f32)event.MouseInput.Y;
cursorDelta.X = (f32)((cursor.X - cursorOld.X) * 1.0);
cursorDelta.Y = (f32)((cursor.Y - cursorOld.Y) * 1.0);
if (cursorDelta.Y > (88 - cameraAngleOld)) {
cursorOld.Y += (cursorDelta.Y - cursorDeltaOld.Y);
cursorDelta.Y = 88 - cameraAngleOld;
}
if (cursorDelta.Y < (-88 - cameraAngleOld)) {
cursorOld.Y += (cursorDelta.Y - cursorDeltaOld.Y);
cursorDelta.Y = -88 - cameraAngleOld;
}
cursorDeltaOld.X = cursorDelta.X;
cursorDeltaOld.Y = cursorDelta.Y;
cameraOrbit = (f32)((int)(cameraOrbitOld + cursorDelta.X) % 360);
cameraAngle = (f32)((int)(cameraAngleOld + cursorDelta.Y) % 360);
if(cameraAngle > 88) cameraAngle = 88;
if(cameraAngle < -88) cameraAngle = -88;
}
}
return false;
}
return false;
}
};
vector3df sphericalXYZ(f32 compassAngle, f32 elevationAngle, f32 radius){
compassAngle = compassAngle * -1;
elevationAngle = elevationAngle * -1;
elevationAngle = elevationAngle + 90;
f32 x = radius * cos(compassAngle * PI/180.0f ) * sin(elevationAngle * PI/180.0f );
f32 z = radius * sin(compassAngle * PI/180.0f ) * sin(elevationAngle * PI/180.0f );
f32 y = radius * cos(elevationAngle * PI/180.0f );
vector3df result;
result.X = x;
result.Y = y;
result.Z = z;
return result;
}
int main()
{
MyEventReceiver rv;
IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2d<u32>(800,600),32,false,false,false, &rv);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
ICursorControl* CursorControl = device->getCursorControl();
CursorControl->setVisible(false);
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;
device->setWindowCaption(L"Irrlicht Custom Scene Node!");
IGUIStaticText* debug_panel = guienv->addStaticText(L"Hello World",rect<s32>(5, 5, 200, 200),false,true,0,-1,false);
ISceneNode* cPivot1 = smgr->addCubeSceneNode(0.5,0,-1,vector3df(playerX,playerY,playerZ));
cPivot1->setMaterialTexture(0,driver->getTexture("media/wall.bmp"));
cPivot1->setMaterialFlag(video::EMF_LIGHTING, false);
ISceneNode* cPivot2 = smgr->addCubeSceneNode(2,cPivot1,-1,vector3df(0,1,0));
cPivot2->setMaterialTexture(0,driver->getTexture("media/wall.bmp"));
cPivot2->setMaterialFlag(video::EMF_LIGHTING, false);
ISceneNode* cPivot3 = smgr->addCubeSceneNode(1,cPivot2,-1,vector3df(0,0,2));
cPivot3->setMaterialTexture(0,driver->getTexture("media/wall.bmp"));
cPivot3->setMaterialFlag(video::EMF_LIGHTING, false);
ICameraSceneNode* myCamera = smgr->addCameraSceneNode(cPivot1, sphericalXYZ(cameraOrbit,cameraAngle,cameraDistance), cPivot1->getPosition());
while(device->run())
{
if(keys[KEY_ESCAPE])
{
device->closeDevice();
}
if(keys[KEY_KEY_W])
{
vector3df playerStep = sphericalXYZ(cameraOrbit,0,playerMoveSpeed);
playerX -= playerStep.X;
playerY -= playerStep.Y;
playerZ -= playerStep.Z;
playerTurnTo = cameraOrbit - 90;
if(playerTurnTo < 0) playerTurnTo += 360;
if(playerTurnTo >= 360) playerTurnTo -= 360;
if(playerCompass < 0) playerCompass = playerCompass + 360;
if(playerCompass >= 360) playerCompass = playerCompass - 360;
f32 playerTurnDir = 0;
f32 playerTurnDelta = 0;
if(playerCompass > playerTurnTo)
{
if(playerCompass - playerTurnTo < 180)
{
playerTurnDir = -1;
playerTurnDelta = playerCompass - playerTurnTo;
}
else
{
playerTurnDir = 1;
playerTurnDelta = (360 - playerCompass) + playerTurnTo;
}
}
if(playerCompass < playerTurnTo)
{
if(playerTurnTo - playerCompass < 180)
{
playerTurnDir = 1;
playerTurnDelta = playerTurnTo - playerCompass;
}
else
{
playerTurnDir = -1;
playerTurnDelta = (360 - playerTurnTo) + playerCompass;
}
}
f32 playerTurnAmount;
if(playerTurnDelta < playerTurnSpeed)
{
playerTurnAmount = playerTurnDelta;
}
else
{
playerTurnAmount = playerTurnSpeed;
}
playerCompass += (playerTurnAmount * playerTurnDir);
cPivot1->setPosition(vector3df(playerX,playerY,playerZ));
cPivot2->setRotation(vector3df(0,playerCompass,0));
myCamera->setTarget(vector3df(playerX,playerY,playerZ));
}
myCamera->setPosition(sphericalXYZ(cameraOrbit,cameraAngle,cameraDistance));
stringw s(L"FPS : "); s += driver->getFPS();
s += L"\nleft mouse button : "; s += mouseDownL;
s += L"\nmiddle mouse button : "; s += mouseDownM;
s += L"\nright mouse button : "; s += mouseDownR;
s += L"\nlast wheel movement : "; s += lastWheelMovement;
s += L"\ncursor x : "; s += cursor.X;
s += L"\ncursor y : "; s += cursor.Y;
s += L"\ncursorOld x : "; s += cursorOld.X;
s += L"\ncursorOld y : "; s += cursorOld.Y;
s += L"\ncursorDelta x : "; s += cursorDelta.X;
s += L"\ncursorDelta y : "; s += cursorDelta.Y;
s += L"\ncamera orbit : "; s += cameraOrbit;
s += L"\ncamera angle : "; s += cameraAngle;
s += L"\nplayer compass : "; s += playerCompass;
s += L"\nplayer turn to : "; s += playerTurnTo;
debug_panel->setText(s.c_str());
driver->beginScene(true, true, SColor(0,120,120,120));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
I don't even get a drawing window - irrlicht doesn't even print its own debug text such as build number and whatnot before it instantly dies.
Just a blank console with a blinking cursor, it's not waiting for input (I've double checked that more than once by reading the code and attempting input, the former yielded nothing, and the latter did nothing - it isn't accepting input at all (besides, if it was waiting for input that'd use cpu cycles, it isn't)).
My main project I'd inject this camera into once it works compiles just fine, it's just this one singular program that fails to run properly.
I'd almost wager it's a bug with mingw (gcc-4.8.1-tdm) at this point - something in the code causes it to never even reach the __start point of the program, so it never uses any cpu and just sits there - since it never reached __start it can't quit either.
If someone could verify this or help me solve it that'd be just swell, I've gone through the code with a fine-tooth comb and can't find the problem.
This is not what normal program behavior looks like:
And obligatory irrlicht version: 1.8.3 (stable branch, right from the downloads section)