ITexture is giving Access Violation Error
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...
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
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");
// ...
}
Travis
Exactly what I wrote 4 or 5 posts before...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.
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
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.
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.
Re: ITexture is giving Access Violation Error
I still have the same problem. but my reading location is 0x00000001 instead of 0x00000000
it doesn't matter where I use getTexture command, I get this error anyway!
Code: Select all
0xC0000005: Access violation reading location 0x00000001
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: ITexture is giving Access Violation Error
You probably have an out-of-bounds array access somewhere. This overwrites your pointer and leaves the 1 there.