irrSpintz...

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
kickBack
Posts: 13
Joined: Sat Jan 14, 2006 2:20 pm

irrSpintz...

Post by kickBack »

This ain't realy a irrlicht bug (mayb) this is an irrSpintz bug :)
But i hope you can help me.
So here is the problem:

Game.ccp

Code: Select all

#include "StdAfx.h"
#include "Game.h"
#include <irrlicht.h>



CGame *CGame::m_theGame;

	IrrlichtDevice *device;
	ICameraSceneNode *cam;


int CGame::Init()
{
	// Init the Irrlicht engine
	//device = createDevice(EDT_DIRECTX9, dimension2d<s32>(1024, 768), 32, false, true,true, this);
	SIrrlichtCreationParameters params;
	params.DriverType = EDT_DIRECTX9;
	params.WindowSize = core::dimension2d<s32>( 800, 600 );
	params.AntiAlias = true;
	params.EventReceiver = this;
	IrrlichtDevice* device = createDeviceEx( params );

		 driver = device->getVideoDriver();
	 smgr = device->getSceneManager();
	 guienv = device->getGUIEnvironment();
	 	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
	//cam = smgr->addCameraSceneNodeFPS(0,100.0f,400.0f);
cam = smgr->addCameraSceneNode();
	cam->setPosition( core::vector3df(0,100,0) );
	cam->setTarget( core::vector3df(0,0,10) );
	cam->setFarValue(12000.0f);	
	m_theGame = this;

	Prepare();

	//s32 lastFPS = -1;
//MainLoop();
	while (device->run())
	{
MainLoop();
	}
	device->drop();
		return 0;

}





void CGame::setUpBattleHUD()
{
statusText = guienv->addStaticText(L"Prepearing...", rect<s32>(10, 10, 400, 40),false,true,0,-1,true);
int height = driver->getScreenSize().Height-driver->getScreenSize().Height/4;
gui::IGUITabControl* tabctrl = guienv->addTabControl(core::rect<int>(0,height,driver->getScreenSize().Width,driver->getScreenSize().Height),
		0, true, true);
	//gui::IGUITab* 
		handTab = tabctrl->addTab(L"Hand");
IGUIImage *card1 = guienv->addImage(rect<s32>(10, 10, 100,140), handTab, -1, L"");
card1->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *card2 = guienv->addImage(rect<s32>(110, 10, 200,140), handTab, -1, L"");
card2->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *card3 = guienv->addImage(rect<s32>(210, 10, 300,140), handTab, -1, L"");
card3->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *card4 = guienv->addImage(rect<s32>(310, 10, 400,140), handTab, -1, L"");
card4->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *card5 = guienv->addImage(rect<s32>(410, 10, 500,140), handTab, -1, L"");
card5->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *card6 = guienv->addImage(rect<s32>(510, 10, 600,140), handTab, -1, L"");
card6->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));

guienv->addButton(rect<s32>(680, 20, 780, 60), handTab, 100, L"Draw");
guienv->addButton(rect<s32>(680, 70, 780, 110), handTab, -1, L"Drop");

gui::IGUITab* bonusTab = tabctrl->addTab(L"Special");
IGUIImage *spell1 = guienv->addImage(rect<s32>(10, 10, 100,140), bonusTab, -1, L"");
spell1->setImage(guienv->getVideoDriver()->getTexture("../media/spellPics/empty.jpg"));
IGUIImage *spell2 = guienv->addImage(rect<s32>(110, 10, 200,140), bonusTab, -1, L"");
spell2->setImage(guienv->getVideoDriver()->getTexture("../media/spellPics/empty.jpg"));
IGUIImage *spell3 = guienv->addImage(rect<s32>(210, 10, 300,140), bonusTab, -1, L"");
spell3->setImage(guienv->getVideoDriver()->getTexture("../media/spellPics/empty.jpg"));
IGUIImage *spell4 = guienv->addImage(rect<s32>(310, 10, 400,140), bonusTab, -1, L"");
spell4->setImage(guienv->getVideoDriver()->getTexture("../media/spellPics/empty.jpg"));
IGUIImage *spell5 = guienv->addImage(rect<s32>(410, 10, 500,140), bonusTab, -1, L"");
spell5->setImage(guienv->getVideoDriver()->getTexture("../media/spellPics/empty.jpg"));
IGUIImage *spell6 = guienv->addImage(rect<s32>(510, 10, 600,140), bonusTab, -1, L"");
spell6->setImage(guienv->getVideoDriver()->getTexture("../media/spellPics/empty.jpg"));

gui::IGUITab* activeTab = tabctrl->addTab(L"Active");
IGUIImage *active1 = guienv->addImage(rect<s32>(10, 10, 100,140), activeTab, -1, L"");
active1->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *active2 = guienv->addImage(rect<s32>(110, 10, 200,140), activeTab, -1, L"");
active2->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *active3 = guienv->addImage(rect<s32>(210, 10, 300,140), activeTab, -1, L"");
active3->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *active4 = guienv->addImage(rect<s32>(310, 10, 400,140), activeTab, -1, L"");
active4->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *active5 = guienv->addImage(rect<s32>(410, 10, 500,140), activeTab, -1, L"");
active5->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *active6 = guienv->addImage(rect<s32>(510, 10, 600,140), activeTab, -1, L"");
active6->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *active7 = guienv->addImage(rect<s32>(610, 10, 700,140), activeTab, -1, L"");
active7->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));
IGUIImage *active8 = guienv->addImage(rect<s32>(710, 10, 800,140), activeTab, -1, L"");
active8->setImage(guienv->getVideoDriver()->getTexture("../media/monsterPics/empty.jpg"));

guienv->addButton(rect<s32>(810, 10, 910, 50), activeTab, -1, L"Kill");
guienv->addButton(rect<s32>(810, 60, 910, 100), activeTab, -1, L"Move");
guienv->addButton(rect<s32>(810, 110, 910, 140), activeTab, -1, L"Attack");


gui::IGUITab* deadTab = tabctrl->addTab(L"Dead");
}
void CGame::Prepare()
{
//////////////=========================================////////////////////////
  
	video::ITexture* terrainTexture = driver->getTexture( "../media/drygrass1.jpg" );
	video::ITexture* detailTexture = driver->getTexture( "../media/detailmap.jpg" );

	scene::ITiledTerrainSceneNodeManager* terrainManager = smgr->addTiledTerrainSceneNodeManager( 128, 4, 4 );
	scene::ITerrainSceneNode* tNode;

	// For loop to load all tiles of the terrain
	core::stringc filenamePrefix = "../media/tile_";
	core::stringc filenameSuffix = ".bmp";
	for( s32 x = 0; x < 4; x++ )
	{
		for( s32 z = 0; z < 4; z++ )
		{
			core::stringc filename = "";

			filename = filenamePrefix;
			filename += x;
			filename += "_";
			filename += z;
			filename += filenameSuffix;

			printf( "Loading terrain tile [%2d][%2d]...\n", x, z );

			// Here we tell the terrain manager to load a tile at the specified position
			terrainManager->LoadTile( x, z, filename.c_str() );

			// Here, we're getting the pointer to the tile we just added and then, since we aren't
			// using any lights, set the material lighting flag to false.  We then set the 2 textures,
			// the first being our standard texture, and the second being the detail texture.  Then
			// we scale the 2nd texture coordinates, so our detail map will repeat 10x over to show
			// even more detail.
			tNode = terrainManager->GetTileNode( x, z );
			tNode->setMaterialFlag( video::EMF_LIGHTING, false );
			tNode->getMaterial(0).AnisotropicFilter = true;
			tNode->getMaterial(0).AnisotropyLevel = 16;
			tNode->setMaterialTexture( 0, terrainTexture );
			tNode->setMaterialTexture( 1, detailTexture );
			tNode->setMaterialType( video::EMT_DETAIL_MAP );
			tNode->scaleTexture( 1, 10.0f );
		}
	}

	// Here we change the scale, position and rotation of all the tiles the terrain manager is 
	// managing.  
	// We scale each tile 24x in the X and Z directions, and 8x in the Y direction.
	terrainManager->setScale( core::vector3df( 24,8,24 ) );
	// Set the position back -100 units in the X and Z directions, so that point -100,0,100 is now our
	// world origin for the rotation of all the terrain tiles.
	terrainManager->setPosition( core::vector3df( -100, 0, -100 ) );
	// Rotate all of the terrain tiles 90 degrees around the Y axis.  This will set the rotation pivot
	// point for each tile node and rotate it, so that the terrain stays "glued" together.  The default
	// behavior for terrain nodes is to rotate around each of their center, the terrain manager handles
	// all of this for you.
	terrainManager->setRotation( core::vector3df( 0, 90, 0 ) );

	// To make the user be able to switch between normal and wireframe mode and solid and detail map,
	// we create an instance of the event reciever from above and let Irrlicht know about it. In 
	// addition, we add the skybox which we already used in lots of Irrlicht examples.

	// create event receiver
//	MyEventReceiver receiver( terrainManager );
	//device->setEventReceiver( &receiver );

  	// create skybox
	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);

	smgr->addSkyBoxSceneNode(
		driver->getTexture("../media/irrlicht2_up.jpg"),
		driver->getTexture("../media/irrlicht2_dn.jpg"),
		driver->getTexture("../media/irrlicht2_lf.jpg"),
		driver->getTexture("../media/irrlicht2_rt.jpg"),
		driver->getTexture("../media/irrlicht2_ft.jpg"),
		driver->getTexture("../media/irrlicht2_bk.jpg")
	);

	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);


/////////////==========================================////////////////////////
}





////////////////////////////*

void CGame::MainLoop()
{

	
Render();

}


void UpdateCamera() 
{       
IVideoDriver* driver;
	ISceneManager* smgr;
	IGUIEnvironment* guienv;
	 driver = device->getVideoDriver();
	 smgr = device->getSceneManager();
	 guienv = device->getGUIEnvironment();
	// make the camera look to a fixed point (45 degrees down) 
   // in front of it, so it wont stay locked on the old target. 
   vector3df cpos = cam->getPosition(); 
   cpos.Z += 2; 
   cpos.Y -= 2; 
   cam->setTarget(cpos); 

   // get the cursor positions 
 //  int xx = device->getCursorControl()->getPosition().X; 
  // int yy = device->getCursorControl()->getPosition().Y; 
//device->getCursorControl();
 int xx =0;; 
 int yy =0; 
   // make the move distance the same for different frame rates 
  int fps = driver->getFPS(); 
   float dist; 

   if (fps > 1) 
                                dist = 2000.0f / fps; 
   else 
      dist = 1.0f;    
    
   if (xx > (driver->getScreenSize().Width- 5)) 
   {    
      cpos = cam->getPosition();       
      cpos.X += dist; 
      cam->setPosition(cpos);                         
   } 
   else if (xx < 5) 
   {    
      cpos = cam->getPosition();       
      cpos.X -= dist; 
      cam->setPosition(cpos);                      
   } 

   if (yy < 5) 
   { 
      cpos = cam->getPosition();       
      cpos.Z += dist; 
      cam->setPosition(cpos);                         
   } 
   else if (yy > (driver->getScreenSize().Height - 50)) 
   {    
      cpos = cam->getPosition();       
      cpos.Z -= dist; 
      cam->setPosition(cpos);                      
   } 
} 
void CGame::Render()
{


	//	if (device->isWindowActive())
	//	{
			driver->beginScene(true, true, 0 );
//
		//	UpdateCamera();
			smgr->drawAll();
			guienv->drawAll();

			driver->endScene();
device->getCursorControl()->setVisible(false);
			// display frames per second in window title
	//		s32 fps = driver->getFPS();
		//	//if (lastFPS != fps)
	//		{
	//			core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
	//			str += driver->getName();
	//			str += "] FPS:";
	//			str += fps;
//
	//			device->setWindowCaption(str.c_str());
				//lastFPS = fps;
		//	}
	//	}
}

void CGame::Finish()
{

	device->drop();
}

//////////////////////////////////////////////////////////////////////////
// Irrlicht event receiver
//////////////////////////////////////////////////////////////////////////

bool CGame::OnEvent(SEvent event)
{
	if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = device->getGUIEnvironment();

			switch(event.GUIEvent.EventType)
			{
	case EGET_BUTTON_CLICKED:

				switch(id)
				{
				case 100:
					{
						io::IXMLReader* xml = device->getFileSystem()->createXMLReader(
		"../media/monsters/monster.xml");

	while(xml && xml->read())
	{
		switch(xml->getNodeType())
		{
		case io::EXN_TEXT:
			// in this xml file, the only text which occurs is the messageText
			MessageText = xml->getNodeData();
			break;
		case io::EXN_ELEMENT:
			{
				if (core::stringw("Model") == xml->getNodeName())
					ModelFile = xml->getAttributeValue(L"file");
				else
				if (core::stringw("messageText") == xml->getNodeName())
					Caption = xml->getAttributeValue(L"caption");
			}
			break;
		}
	}


createMonster(ModelFile.c_str());
	if (xml)
		xml->drop(); // don't forget to delete the xml reader 



							//	Model->setScale(scale);
					}
					break;
				}

				break;
			}
		}
	if ( event.EventType == irr::EET_KEY_INPUT_EVENT&&	
		!event.KeyInput.PressedDown)
	{	
		switch(event.KeyInput.Key)	
		{	
		case KEY_ESCAPE:	
			
			{		
				device->closeDevice();
			}	
			return true;	
		}
	} 
	return false; 
} 
Game.h

#include "StdAfx.h"
//#include "CAudierePlayer.h"



#if !defined(GAME_H)
#define GAME_H

class IrrBox;

Code: Select all

class CGame : public IEventReceiver {
protected:
	// misc
	int lastFPS;
	u32 lasttick;


public:
	// Irrlicht  vars
	IVideoDriver* driver;
	ISceneManager* smgr;
	IGUIEnvironment* guienv;

	scene::ITriangleSelector *triSelector;

	scene::IBillboardSceneNode * bill;
	scene::ISceneNode* selectedSceneNode;
	scene::ISceneNode* lastSelectedSceneNode ;
		video::SMaterial material;
	

	// Scene vars


	IGUIStaticText *statusText;

IGUITab* handTab;

	//////////////////////////////////////////////////////////////////////////
	// Irrlicht Callbacks
	virtual bool OnEvent(SEvent event);

	
	static CGame *m_theGame;
	//////////////////////////////////////////////////////////////////////////
string<wchar_t> text;

ITimer* timer;




ISceneNodeAnimatorCollisionResponse* levelCollision;

ISceneNode* levelNode;
ITriangleSelector* levelNodeTS;

//bool shooting = false;





	//////////////////////////////////////////////////////////////////////////
	// Game Functions
	int Init();
	void Prepare();
	void loadModel(const c8* fn);
	void setUpBattleHUD();
	
	void setUpLoadingScreen();
	void MainLoop();

	void Render();

	void Finish();




	core::stringc ModelFile;
core::stringw MessageText;
core::stringw Caption;
IAnimatedMeshSceneNode* Model;
scene::ISceneNode* SkyBox;
	//////////////////////////////////////////////////////////////////////////
	// Game functions


	
	

	
};

#endif
main .ccp

Code: Select all

#include "Game.h"
class CGame Game;

int main(int argc, char* argv[])
{
	// Init game
	//Game.device->drop();
	Game.Init();
	//Game.Init();
	// Create scene
	//Game.Prepare();
 
	// Main Loop


	// Clean up
//	Game.Finish();

	return 1;
}


I was just experimenting with the code pieces with irrlicht and then i switxhed to spintz(yesterday) and now everything brokes down when i call device from any other location then Init().
I don't know what to do... :oops:
[/code]
kickBack
Posts: 13
Joined: Sat Jan 14, 2006 2:20 pm

Post by kickBack »

I realy need HELP with this.
I'm not the best programmer and i cant find a solution for this problem.
//////////+++++++++++++++++++++++++\\\\\\\\\\\\\
Have anyone else got this problem?
:?
I have tried to implant the irrSpintz into the irrlicht techdemo and its impossible couse i get the same error after the device function is called from anywhere else then its creation location
:(
Guest

Post by Guest »

first off, don't bump your thread after only ONE HOUR.

if it is an irrspintz issue (and your in that big of a hurry) amybe you ought to shoot an p.m. to Spintz with a VERY POLITE TONE
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I hope you feel like a retard after seeing the answer... :)

Code: Select all

IrrlichtDevice *device; 

int CGame::Init() 
{ 
   // Init the Irrlicht engine 
   //device = createDevice(EDT_DIRECTX9, dimension2d<s32>(1024, 768), 32, false, true,true, this);

   // code omitted for brevity.
   IrrlichtDevice* device = createDeviceEx( params ); 

   // use device here...
You create a local device pointer inside CGame::Init and then use it. You never initialize the global device pointer. You used to do this in the old code that you commented out.
kickBack
Posts: 13
Joined: Sat Jan 14, 2006 2:20 pm

Post by kickBack »

Thanks.
:oops:
Didn't saw that.
Post Reply