my code doesnt work

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
Mr.Gluck
Posts: 82
Joined: Tue Aug 31, 2004 8:02 pm

my code doesnt work

Post by Mr.Gluck »

When I press ESC the device must be dropped, aber it only halts... whats wrong, what mistake i have don?

Code: Select all

+++main.cpp+++

#include "main.h"
#include "CMainMenu.h"

int main()
{
CMainMenu m_menu;
m_menu.run();
return 0;
}



+++main.h+++
#ifndef __MAIN_H_INCLUDED__
#define __MAIN_H_INCLUDED__

//#pragma once

#include "include/irrlicht.h"
using namespace irr;


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


static IrrlichtDevice *device =0;
static IVideoDriver *driver = 0;
static ISceneManager* game_scene = 0;	
static scene::ISceneManager* menu_scene = 0; 

static bool main_menu = true;
static bool game_menu = false;
static bool game = true;

static bool mouse_left_click = false;
static bool mouse_right_click = false;
static s32 mouseX = 0;
static s32 mouseY = 0; 

#endif


+++CMainMenu.cpp+++
#include <windows.h>
#include "CMainMenu.h"

#pragma comment(lib, "lib/Irrlicht.lib")
#include <stdio.h>

bool CMainMenu::OnEvent(SEvent event)
{
 	if(event.EventType == irr::EET_KEY_INPUT_EVENT)
      {

		   if(!event.KeyInput.PressedDown)
         {
            switch(event.KeyInput.Key)
            {
               case KEY_ESCAPE:
               {
                 
				   device->closeDevice();   
              } }
		 }} 
		
	return false;
 };

bool CMainMenu::run()
{

device = createDevice(EDT_OPENGL, dimension2d<s32>(1024, 768), 32, false, false, false,this);
device->setResizeAble(true); 

	 driver = device->getVideoDriver();
	 menu_scene = device->getSceneManager(); 


while(device->run) 
{

driver->beginScene(true, true, SColor(0,0,0,0));
menu_scene->drawAll();
driver->endScene();

	}
device->drop();
return true;
}



+++CMainMenu.h+++
#ifndef __C_MAIN_MENU_H_INCLUDED__
#define __C_MAIN_MENU_H_INCLUDED__

#include "main.h"



class CMainMenu : public IEventReceiver
{
public:


bool run();
virtual bool OnEvent(SEvent event);

private:



};

#endif
 

bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Does a "return true;" after your device->closeDevice() line fixes the problem?
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Mr.Gluck
Posts: 82
Joined: Tue Aug 31, 2004 8:02 pm

Post by Mr.Gluck »

bal wrote:Does a "return true;" after your device->closeDevice() line fixes the problem?
\

of course, no... if you compile it, you'll see that cursor icon is sand watch. The problem somewhere else.
Harry_Mystic
Posts: 32
Joined: Sun Nov 23, 2003 10:23 pm

Post by Harry_Mystic »

Does it work if you add a "break;" after "device->closeDevice;" :?:

Just a question:
Is there any advantage to put all this bool, drivers etc. in a main.h ? I usually make them private class members (any disadvantage here?).
And must these are static?

Thanks in advance
Mr.Gluck
Posts: 82
Joined: Tue Aug 31, 2004 8:02 pm

Post by Mr.Gluck »

Harry_Mystic wrote:Does it work if you add a "break;" after "device->closeDevice;" :?:

Just a question:
Is there any advantage to put all this bool, drivers etc. in a main.h ? I usually make them private class members (any disadvantage here?).
And must these are static?

Thanks in advance

Ok, I try to explain it as I can in english.

No, the problem not in Event class... I have add "break", but it not resovled a problem. For more understanding you must know, that Windows XP says, that this program(this code) is not responding.

Why static? Because it compiles ONLY if I use wors STATIC. The problem is I dont understand how to devide the source to many files, such as main.cpp, main.h, CMainMenu.cpp, CMainMenu.h, CGameMenu.cpp and so on. And for this i put all general variables to main.h.
Simply, I dont understand which variables must be ONLY ONE TIME INITIALISED and where I must keep them.

And about this code. After deviding and rearranging code I got that application draws a main menu, but doesnt corresponding and mouse icon is sand watch.

So, the problem somewhere in structure, i think, because before deviding it works perfectly... but i didnt make a back up ;(
T101
Posts: 44
Joined: Thu Jul 29, 2004 4:41 pm

Post by T101 »

Hmmm.

I think a little explanation of functions and function pointers is in order here...

When you write:

Code: Select all

while(device->run)
What you are doing is checking if a pointer is unequal to 0 - the pointer to the binary code of the run() function.

Function pointers are written as the name of the function without (), and function calls are written with ().

Try writing it as:

Code: Select all

while(device->run())
Because currently, the device->run() function is not being called. Irrlicht is rendering fulltime, and not processing windows messages.
Mr.Gluck
Posts: 82
Joined: Tue Aug 31, 2004 8:02 pm

Post by Mr.Gluck »

yes, it works.... now i trying to understand it...

snx
Post Reply