IEventReceiver can't using >_<

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
Guest

IEventReceiver can't using >_<

Post by Guest »

hi , all
I using IEventReceiver (I refer to this tutorial http://irrlicht.sourceforge.net/tut004.html)
when run program(follow program) , error happened ...
(my using Application Wizard to set up my project , step follow
(1) File -> New
(2) In Projects tab
(3) Choose Win32 Application
(4) choose a simple Win32 Application
)

very thanks anybody reply ^_^

Error message is follow program
*********************************************************
bool LoadResource(void)
{
// Error happend this line , error message is "unhandled exception in Tank.exe (IRRLICHT.DLL) : 0xC0000005 : Access Violation"
scene::IAnimatedMesh *HumanAniMesh = g_Smgr->getMesh("Test Media/cylinder.x");
scene::IAnimatedMeshSceneNode *HumanNode = g_Smgr->addAnimatedMeshSceneNode(HumanAniMesh, 0, 0);
HumanNode->setMaterialFlag(video::EMF_LIGHTING, false);
scene::ILightSceneNode *LightNode = g_Smgr->addLightSceneNode(0, core::vector3df(-20.0, 0.0, 0.0), video::SColorf(1.0, 1.0, 1.0), 100.0, 21);
scene::ISceneNodeAnimator *FlyCircleAnimator = g_Smgr->createFlyCircleAnimator(core::vector3df(0.0, 0.0, 0.0), 10.0);
LightNode->addAnimator(FlyCircleAnimator);
FlyCircleAnimator->drop();

g_Device->getFileSystem()->addZipFileArchive("Test Media/map-20kdm2.pk3");
scene::IAnimatedMesh *SceneMesh = g_Smgr->getMesh("20kdm2.bsp");
scene::ISceneNode *SceneNode = g_Smgr->addOctTreeSceneNode(SceneMesh->getMesh(0));

return true;
}
*********************************************************

-----------------------------------------------------------------------
----------------------- follow my test program ---------------------
-----------------------------------------------------------------------
// Tank.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

#include <irrlicht.h>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")

bool InitIrrlichtEngine(void);
bool LoadResource(void);
class MyEventReceiver;


IrrlichtDevice *g_Device;
video::IVideoDriver *g_Driver;
scene::ISceneManager *g_Smgr;
gui::IGUIEnvironment *g_GuiEnv;


scene::ISceneNode *node = 0;

class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = node->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
}
}

return false;
}
};


bool InitIrrlichtEngine(void)
{
MyEventReceiver receiver;

// Initial Device
g_Device = createDevice(video::EDT_DIRECTX9, core::dimension2d<s32>(800, 600), 16, false,
false, &receiver);

IrrlichtDevice *device = g_Device;

// 設定視窗的標題
device->setWindowCaption(L"坦克");

// 設置全域變數
g_Driver = device->getVideoDriver();
g_Smgr = device->getSceneManager();
g_GuiEnv = device->getGUIEnvironment();

// 載入的texture , 都一定是16 bit的格式
g_Driver->setTextureCreationFlag(video::ETCF_ALWAYS_16_BIT, true);

return true;
}

bool LoadResource(void)
{
// Error happend this line , error message is "unhandled exception in Tank.exe (IRRLICHT.DLL) : 0xC0000005 : Access Violation"
scene::IAnimatedMesh *HumanAniMesh = g_Smgr->getMesh("Test Media/cylinder.x");
scene::IAnimatedMeshSceneNode *HumanNode = g_Smgr->addAnimatedMeshSceneNode(HumanAniMesh, 0, 0);
HumanNode->setMaterialFlag(video::EMF_LIGHTING, false);
scene::ILightSceneNode *LightNode = g_Smgr->addLightSceneNode(0, core::vector3df(-20.0, 0.0, 0.0), video::SColorf(1.0, 1.0, 1.0), 100.0, 21);
scene::ISceneNodeAnimator *FlyCircleAnimator = g_Smgr->createFlyCircleAnimator(core::vector3df(0.0, 0.0, 0.0), 10.0);
LightNode->addAnimator(FlyCircleAnimator);
FlyCircleAnimator->drop();

// 載入場景. 先將場景的壓縮檔加到File System(這會幫我們解壓縮出裡面的檔案)
// 然後載入場景至IAnimatedMesh , 然後用OctTree Node將mesh包起來
g_Device->getFileSystem()->addZipFileArchive("Test Media/map-20kdm2.pk3");
scene::IAnimatedMesh *SceneMesh = g_Smgr->getMesh("20kdm2.bsp");
scene::ISceneNode *SceneNode = g_Smgr->addOctTreeSceneNode(SceneMesh->getMesh(0));

return true;
}



int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Initial Irrlicht Engine
if(InitIrrlichtEngine() == false) return 0;

if(LoadResource() == false) return 0;

// 此變數給以下的使用
scene::ISceneManager *smgr = g_Smgr;
IrrlichtDevice *device = g_Device;
video::IVideoDriver *driver = g_Driver;
gui::IGUIEnvironment *guienv = g_GuiEnv;

// 看不到滑鼠游標
device->getCursorControl()->setVisible(false);

// 建立FPS的Camera
scene::ICameraSceneNode *CameraNode = smgr->addCameraSceneNodeFPS();
CameraNode->setPosition(core::vector3df(0.0, 10.0, -60.0));

// 加入靜態的文字到視窗
guienv->addStaticText(L"Hope Can Display", core::rect<int>(10,10,200,30), true);

// Render Loop
while(device->run())
{
// Ready Render !!!
driver->beginScene(true, true, video::SColor(128, 100, 100, 100));

// Render All Scene Node
smgr->drawAll();

// Render All GUI
guienv->drawAll();

// End Render !!!
driver->endScene();
}

// 整個程式結束
device->drop();

return 0;
}

very thanks anybody reply ^_^
Guest

Post by Guest »

problem was solved ^^"
thanks anybody glance this thread
Post Reply