"Access violation reading location" while accessing a global vector..

Posted by djzmo on Stack Overflow See other posts from Stack Overflow or by djzmo
Published on 2009-10-15T12:40:22Z Indexed on 2010/04/02 19:33 UTC
Read the original article Hit count: 288

Filed under:
|

Hello there,

-- First of all, I don't know whether the vector can be called as a "global vector" if I declared it under a namespace, but not in a class or function. --

I'm now writing a simple Irrlicht (http://irrlicht.sourceforge.net) wrapper for my game to make things simpler and easier, but recently I got an "Access violation reading location" error when trying to push_back a vector declared in the global scope.

Here is my code so far:

irrwrap.cpp:

namespace irrw
{
	//.........
	IrrlichtDevice *device;
	IVideoDriver *driver;
	irr::core::array<irr::video::ITexture*> TextureCollector;
	vector<int> TextureConnector;
	//.........
}

//..............

void irrInit(int iGraphicsDriver, int iWindowWidth, int iWindowHeight, int iScreenDepth, bool bFullScreen)
{
	E_DRIVER_TYPE drvT;
	if(iGraphicsDriver == GD_SOFTWARE)
		drvT = EDT_SOFTWARE;
	else if(iGraphicsDriver == GD_D3D8)
		drvT = EDT_DIRECT3D8;
	else if(iGraphicsDriver == GD_D3D9)
		drvT = EDT_DIRECT3D9;
	else if(iGraphicsDriver == GD_OPENGL)
		drvT = EDT_OPENGL;

	//..............

	irrw::device = createDevice(drvT, dimension2d<u32>(iWindowWidth, iWindowHeight), iScreenDepth, bFullScreen);
	irrw::driver = irrw::device->getVideoDriver();
	//..................
}

void irrLoadImage(irr::core::stringc szFileName, int iID, int iTextureFlag)
{
	//........
	irrw::TextureCollector.push_back(irrw::driver->getTexture(szFileName)); // the call stack pointed to this line
	irrw::TextureConnector.push_back(iID);
}

main.cpp:

//.........
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
{
	//.........
	irrInit(GD_OPENGL, 800, 600, 16, false);
	irrLoadImage("picture.jpg", 100, 1);
	//.........
}

and the error:

Unhandled exception at 0x692804d6 in Game.exe: 0xC0000005: Access violation reading location 0x00000558.

Now I really got no idea on how to fix the problem.

Any kind of help would be appreciated :)

Here are some prototypes:

	virtual ITexture* getTexture(const io::path& filename) = 0;
	typedef core::string<fschar_t> path; // under 'io' namespace
	typedef char fschar_t;
	typedef string<c8> stringc;
	typedef char c8;

Just FYI, I am using MSVC++ 2008 EE.

(CODE UPDATED)

© Stack Overflow or respective owner

Related posts about c++

Related posts about irrlicht