ITexture is giving Access Violation Error

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.

Postby hybrid » Thu May 25, 2006 8:39 pm

These definitions cannot be global because global variables cannot be initialized by method calls. So there are probably hundreds of errors due to these statements. Try to avoid global definitions or be really sure what you're doing!
hybrid
Admin
 
Posts: 13946
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Postby vitek » Thu May 25, 2006 9:19 pm

First off, it is probably best if you avoid the use of global variables if you can. It appears that the problem you have is that you have declared a global and a local variable with the same name. When you initialize the local variable, it has no effect on the global. At some time later in your program, you access the global, but it was never initialized.

If you wish to continue using globals, you should do this...

Code: Select all
// the header file declares the variables
extern IrrlichtDevice *MainDevice; //The Main Irrlicht Device
extern ISceneManager *Scene; //Scene Manager
extern IVideoDriver *Driver; //Video Driver
extern IGUIEnvironment *GUI; //GUI Environment
extern ITexture *BGTex;


Code: Select all
// the source file defines the variables
IrrlichtDevice *MainDevice = 0;
ISceneManager *Scene = 0;
IVideoDriver *Driver = 0;
IGUIEnvironment *GUI = 0;
ITexture *BGTex = 0;


Code: Select all
// the initialization routine initializes the variables
void initSystems()
{
  IEventReceiver* eventReceiver = new EventReceiver;
  MainDevice= createDevice(EDT_DIRECT3D9, dimension2d<s32>(800, 600), 16, false, true, false, eventReceiver);

  Scene = MainDevice->getSceneManager();
  Driver = MainDevice->getVideoDriver();
  GUI = MainDevice->getGUIEnvironment();
}

void initMenu()
{
  // ...
  BGTex = Driver->getTexture("2D Images/Menu/BG.bmp");
  // ...
}


Another thing that you might want to consider doing is adding a prefix to your variable names so you know what scope they are from. Using a g to indicate global and m for member. That will help to avoid some naming issues in the future.

Travis
User avatar
vitek
Bug Slayer
 
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Postby Acki » Thu May 25, 2006 10:05 pm

vitek wrote:It appears that the problem you have is that you have declared a global and a local variable with the same name. When you initialize the local variable, it has no effect on the global. At some time later in your program, you access the global, but it was never initialized.

Exactly what I wrote 4 or 5 posts before... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
User avatar
Acki
 
Posts: 3474
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)

Postby vitek » Fri May 26, 2006 5:37 am

Yeah, I know. Unfortunately most beginners don't understand all of the big words you throw at them. Sometimes easiest way is to show them.

Travis
User avatar
vitek
Bug Slayer
 
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Postby Xharock » Fri May 26, 2006 6:17 am

Don't worry Acki I knew what you meant :)
Thanks for your help. I'm a begginner to bigger projects. I've only ever done small mini things never something on such a big scale. Thanks again. Oh and I am now in the process of removing many of my global variables. My BGTex doesn't need to be global as only one module will be using it.
Xharock
 
Posts: 71
Joined: Wed May 10, 2006 3:50 pm

Postby Xharock » Fri May 26, 2006 6:25 am

I can't beleive this still don't work... nevermind. I'm scrapping that and starting over. And try and get it all OK. This was poorly designed.
Xharock
 
Posts: 71
Joined: Wed May 10, 2006 3:50 pm

Postby Xharock » Fri May 26, 2006 5:00 pm

Yay! I have re-started and re-designed my code layout and all is working nicely. I'm thinking of incorporating some sort of class. But thanks for ally our help!
Xharock
 
Posts: 71
Joined: Wed May 10, 2006 3:50 pm

Re: ITexture is giving Access Violation Error

Postby iRobo » Mon Jan 23, 2012 9:24 pm

I still have the same problem. but my reading location is 0x00000001 instead of 0x00000000

cpp Code: Select all
0xC0000005: Access violation reading location 0x00000001


it doesn't matter where I use getTexture command, I get this error anyway!
iRobo
 
Posts: 26
Joined: Mon Aug 23, 2010 1:41 pm
Location: Iran

Re: ITexture is giving Access Violation Error

Postby hybrid » Mon Jan 23, 2012 10:29 pm

You probably have an out-of-bounds array access somewhere. This overwrites your pointer and leaves the 1 there.
hybrid
Admin
 
Posts: 13946
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Previous

Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest