Switched from Dev-C++ to MSVC++ Express, and...

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
Riceman
Posts: 9
Joined: Tue Dec 30, 2008 8:40 pm

Switched from Dev-C++ to MSVC++ Express, and...

Post by Riceman »

...my program promptly broke.

Everything is linked correctly (I believe), and my program compiles, but when I try and run it it gives me the old "Windows needs to close ...." message.

As a test, I compiled and ran a few of the tutorials successfully. I also compiled and ran an irrKlang tutorial successfully.

I have no idea what's going on here. Can anyone help?

Code: Select all

/*

Heroes of Western Keep v0.01

*/

#include <irrlicht.h>
#include <irrKlang.h>
#include <iostream>

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

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "irrKlang.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

class MyEventReceiver : public IEventReceiver
{
public:
	// This is the one method that we have to implement
	virtual bool OnEvent(const SEvent& event)
	{
		// Remember whether each key is down or up
		if (event.EventType == EET_KEY_INPUT_EVENT)
			KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;

		return false;
	}

    // This is used to check whether a key is being held down
    virtual bool IsKeyDown(EKEY_CODE keyCode) const
    {
            return KeyIsDown[keyCode];
    }
    
    MyEventReceiver()
    {
            for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                    KeyIsDown[i] = false;
    }

private:
	// We use this array to store the current state of each key
	bool KeyIsDown[KEY_KEY_CODES_COUNT];
};

int main()
{
	E_DRIVER_TYPE videoType = EDT_SOFTWARE;
	dimension2d<u32> resolution = dimension2d<u32>(800,600);

     // Set up devices and event receiver
	MyEventReceiver receiver;
        
	IrrlichtDevice *device = createDevice(videoType,resolution, 32, false, false, false, &receiver);

	if (!device)
		return 1; // could not create driver.
		
	// start the sound engine with default parameters
	ISoundEngine* audioEng = createIrrKlangDevice();
	
	if (!audioEng)
		return 1; // could not start audio.
		
    ISceneManager* smgr = device->getSceneManager();

	device->setWindowCaption(L"Heroes of Western Keep");
	
	device->getCursorControl()->setVisible(false);

	IVideoDriver* driver = device->getVideoDriver();
	
	ITexture* images = driver->getTexture("media/sprites.png"); //Load sprites
	ITexture* GUIimage = driver->getTexture("media/interface.png"); // Load interface texture
	ITexture* GUIbg = driver->getTexture("media/uibackground.png"); // Load background texture
	driver->makeColorKeyTexture(images, position2d<s32>(0,0)); //Set alpha color
	driver->makeColorKeyTexture(GUIimage, position2d<s32>(200,100)); //Set alpha color
	
	// Set up fonts
	
	IGUIFont* biFont = device->getGUIEnvironment()->getBuiltInFont();
	IGUIFont* displayFont = device->getGUIEnvironment()->getFont("media/DisplayFont.png");
	IGUIFont* menuFont = device->getGUIEnvironment()->getFont("media/MenuFont.png");
		
	int counter = 0;
	
	audioEng->play2D("media/stepintothelight.mp3",true);
		
	while(device->run() && driver)
	{	
		if (device->isWindowActive())
		{		
			u32 time = device->getTimer()->getTime();

			if (counter > -1200 && (time % 50 == 0)) 
				counter--;

			driver->beginScene(true, true, SColor(255,120,102,136));
			
			// draw background
			driver->draw2DImage(GUIbg,position2d<s32>(0,counter),rect<s32>(0,0,800,2000),0,SColor(255,255,255,255),true);
			
			// draw gui
			driver->draw2DImage(GUIimage,position2d<s32>(0,0),rect<s32>(0,0,800,600),0,SColor(255,255,255,255),true);
			
			// draw some text
			if (menuFont)
				menuFont->draw(L"Start Game",
					rect<s32>(275,410,400,450),
					SColor(255,255,255,255));
			
			// draw transparent rect under cursor
			position2d<s32> m = device->getCursorControl()->getPosition();
			driver->draw2DImage(images,m,rect<s32>(2,68,45,110),0,SColor(255,255,255,255), true);

			driver->endScene();
          }
          
		if(receiver.IsKeyDown(KEY_KEY_Q))
			device->closeDevice();
   }
   
   audioEng->drop();
   device->drop();

   return 0;
}
Riceman
Posts: 9
Joined: Tue Dec 30, 2008 8:40 pm

Post by Riceman »

Still haven't been able to figure this one out.

Anyone have at least a guess?
Ben Overmyer
Web Developer, Artist, and Gamer
http://www.manatrance.com
Josie
Posts: 44
Joined: Sat Jul 25, 2009 4:08 am
Location: Griffin, Georgia, US
Contact:

Post by Josie »

not sure- try setting breakpoints and walking through your app until it crashes.
Riceman
Posts: 9
Joined: Tue Dec 30, 2008 8:40 pm

Post by Riceman »

It crashes right after this line:

Code: Select all

IrrlichtDevice *device = createDevice(videoType,resolution, 32, false, false, false, &receiver); 
As far as I'm able to tell, this is correctly put together....
Ben Overmyer
Web Developer, Artist, and Gamer
http://www.manatrance.com
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I guess you're using the wrong Irrlicht or irrKlang DLL in your bin directory. You may also have the wrong working directory set in MSVC, try copying the compiled exe manually and running it from windows explorer.

Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Riceman
Posts: 9
Joined: Tue Dec 30, 2008 8:40 pm

Post by Riceman »

BlindSide wrote:I guess you're using the wrong Irrlicht or irrKlang DLL in your bin directory. You may also have the wrong working directory set in MSVC, try copying the compiled exe manually and running it from windows explorer.

Cheers
This was the problem.

I had the wrong irrlicht.dll file in the Debug directory. After replacing it, the application runs.

Thanks guys!!! =D
Ben Overmyer
Web Developer, Artist, and Gamer
http://www.manatrance.com
Post Reply