   trouble releasing sprites
  I'm trying to make a very basic 2D game engine with DirectX 9 and VC++ 2008 Express. I wanted to make it so that using the engine didn't require me to release all my sprites at the end, so I defined my own sprite class:std::list<LPD3DXSPRITE> _sprs;class SPRITE {public:LPD3DXSPRITE sprite;LPDIRECT3DTEXTURE9 tex;SPRITE() {if (SUCCEEDED(D3DXCreateSprite(_dev, &sprite))) {_sprs.push_back(sprite);}}void LoadTexture(const char* Path) {D3DXCreateTextureFromFile(_dev, Path, &tex);}void Draw(VECTOR Position, VECTOR Center, COLOR Color) {_dev->BeginScene();sprite->Begin(D3DXSPRITE_ALPHABLEND);sprite->Draw(tex, NULL, &D3DXVECTOR3(Center.x, Center.y, 0),&D3DXVECTOR3(Position.x, Position.y, 0),D3DCOLOR_XRGB(Color.R, Color.G, Color.B));sprite->End();_dev->EndScene();_dev->Present(NULL, NULL, NULL, NULL);}};you'll notice that in the SPRITE constructor I had the LPD3DXSPRITE sprite added to the end of a list called _sprs. This is so that I can store all of the sprites I define in a global variable which I can later use to release them all. at the end of the program, I call my releaseSprites() function:void releaseSprites() {if (_sprs.size()>0) {std::list<LPD3DXSPRITE>::iterator itr=_sprs.begin();LPD3DXSPRITE spr;for (unsigned int x=0; x<_sprs.size(); x++) {spr=*itr;spr->Release();++itr;}}}The code compiles and runs, but at the end, when I call this function, I get this error:Quote:Unhandled exception at 0x002f50ad in dx92d.exe: 0xC0000005: Access violation reading location 0x0000000b.What can I do to fix this?   
  Why store all of your textures in a global list?  I would think it would make more sense to let each SPRITE instance clean up its own garbage.  Otherwise it's much easier to run into a situation where a SPRITE is still alive, but its textures have already been released.   ;  Why dont you declare a destructor and have it release the texture and sprites? That way you dont have to have a global list. You add a sprite to the list every time you create a new instance of SPRITE so why not have that same instance clean up its own mess. It doesn't seem like your releasing the texture inside SPRITE or maybe its another function you haven't shown.   