Page 2 of 2

Posted: Thu May 25, 2006 8:39 pm
by hybrid
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!

Posted: Thu May 25, 2006 9:19 pm
by vitek
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

Posted: Thu May 25, 2006 10:05 pm
by Acki
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... ;)

Posted: Fri May 26, 2006 5:37 am
by vitek
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

Posted: Fri May 26, 2006 6:17 am
by Xharock
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.

Posted: Fri May 26, 2006 6:25 am
by Xharock
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.

Posted: Fri May 26, 2006 5:00 pm
by Xharock
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!

Re: ITexture is giving Access Violation Error

Posted: Mon Jan 23, 2012 9:24 pm
by iRobo
I still have the same problem. but my reading location is 0x00000001 instead of 0x00000000

Code: Select all

0xC0000005: Access violation reading location 0x00000001
it doesn't matter where I use getTexture command, I get this error anyway!

Re: ITexture is giving Access Violation Error

Posted: Mon Jan 23, 2012 10:29 pm
by hybrid
You probably have an out-of-bounds array access somewhere. This overwrites your pointer and leaves the 1 there.