   Breakpoints override program crash
  I'm working on repairing my game-engine experiment. I've got some kind of a memory leak in my program, or a buffer overflow. I haven't the faintest clue what's going on, mostly because my debugger seems to fix the problem I am looking for. I am using Visual C++ 2008 With DirectX 9. When I run my program it crashes outbecause I attempt to access a bad pointer somewhere in my rats-nest of code.However, when I try to isolate exactly where the pointer is being corrupted (possibly a bad copy constructor?) everything works fine. All the values are valid and the program behaves admirably. I'm thinking that it's the break points. If I place breakpoints before a certain point in my program, the error doesn't occur. However, if I place a breakpoint past the code that is accessing the bad memory location it crashes out with the same error. I've looked at that code, and to me it doesn't seem to be doing anything wrong, I just haven't protected it against bad values (a programming flaw, but that's why I'mrevamping it, to get rid of this kind of stuff). This problem has me completely floored, and I just wondered if anyone had everrun into something like this, and could give me a few pointers about where tolook. I'd post the code, but it's a bit long. I can say that I am using an iterator to access the object that suddenly becomes invalid on the third passof my main loop through the renderer. I did just switch to manually blitting with textured quads in place of the sprite interface, but the blitter shouldn'teffect the part of the code (it's the animation check on the graphic object),they simply don't interact at all (maybe that's my problem?).Anyway, I would appreciate any insight that anyone could possibly hand me on this one.   
  Maybe show us some code? :p   ;void CORE::cGraphics::Render(float now){m_direct.Clear();m_direct.StartRender();m_sprite.ResetTrans();m_sprite.Start();std::vector<cObject*>::iterator iter;for(iter = m_batch.begin(); iter != m_batch.end(); ++iter){//It skrews up right here!if((*iter)->m_anim.Check((*iter)->m_index)) //loop the animation (all objects are animated)(*iter)->m_anim.Reset((*iter)->m_index);//we do not need to check for null because the Draw command will not accept null valuesif(!CheckTexture((*iter)->m_texture))if((LoadTexture((*iter)->m_texture)==NULL)){std::string s = "Cannot load texture " + ((*iter)->m_texture);Foundation::WinFnd::WinLayer::window->MBox(s.c_str(), "CORE: Critical Error");return;}//m_sprite.Draw(&m_textures[(*iter)->m_texture], *((*iter)->m_anim.GetFrame((*iter)->m_index, now)),(*iter)->m_phys.position.x, (*iter)->m_phys.position.y,(*iter)->m_phys.scale.x, (*iter)->m_phys.scale.y, RAD((*iter)->m_phys.rotation), (*iter)->m_phys.center.x, (*iter)->m_phys.center.y, 1);m_blitter.BlitQuad(&m_textures[(*iter)->m_texture],*((*iter)->m_anim.GetFrame((*iter)->m_index, now)),(*iter)->m_phys.position.x,(*iter)->m_phys.position.y,RAD((*iter)->m_phys.rotation),(*iter)->m_phys.scale.x,(*iter)->m_phys.scale.y,(*iter)->m_phys.center.x,(*iter)->m_phys.center.y, 1);}m_sprite.ResetTrans();//Now render textstd::vector<cText>::iterator titer;for(titer = m_tbatch.begin(); titer != m_tbatch.end(); ++titer){//TODO, CUSTOM TEXT-DRAWINGm_text.SetWindow(titer->GetR());m_text.Draw(titer->GetT(), D3DCOLOR_ARGB(255,255,255,255) , m_sprite.GetSpri());}m_sprite.End();m_tbatch.clear();m_batch.clear();m_direct.EndRender();m_direct.Present();}Okay, that's my render function. I've added a comment where it normally crashes.Here are some of the classes involved:class cGraphics{protected:std::map<std::string, Graphics::DirectX::iTexture> m_textures;Graphics::DirectX::DirectXLayer m_direct;Graphics::DirectX::iSprite m_sprite;Graphics::DirectX::iBlitter m_blitter;Graphics::DirectX::iText m_text;std::vector<cObject*> m_batch;std::vector<cText> m_tbatch;bool CheckTexture(std::string str);public:cGraphics(D3DPRESENT_PARAMETERS para);~cGraphics();Graphics::DirectX::iTexture *LoadTexture(std::string filename);void ReleaseTextureReference(std::string filename);void Flush();void Render(float now);void Draw(cObject *obj);void Print(cText *text);void Print(cText &text);};struct cFrame2d{RECT coords; //texture positionfloat duration;cFrame2d();cFrame2d(RECT r, float d);cFrame2d(const cFrame2d &rhs);void operator=(const cFrame2d &rhs){coords = rhs.coords;duration = rhs.duration;}void Save(std::ofstream &file);void Load(std::ifstream &file);};class cAnimData2d{protected:cFrame2d *m_anim; //This is the actual animationunsigned long size; //This is the size of the animation//Engine varsfloat last;int index;//bool loop; //Looping triggerpublic:cAnimData2d();cAnimData2d(cFrame2d *anim, unsigned long sizea);cAnimData2d(const cAnimData2d &rhs);~cAnimData2d();void operator=(const cAnimData2d &rhs);void Start();void Reset();void Stop();void SetFrame(int i);bool Ended();bool CheckDuration(float now);void Update(float now);RECT *GetFrame(float now);RECT* GetFrame();void Save(std::ofstream &file);void Load(std::ifstream &file);};class cAnimation2d //Holds animation information. Use an array to hold multiple animation{protected:cAnimData2d *m_data; //Pointer to array of animation datasunsigned long m_size;public:cAnimation2d();cAnimation2d(cAnimData2d *data, unsigned long count);cAnimation2d(const cAnimation2d &rhs);void operator=(const cAnimation2d &rhs);~cAnimation2d();RECT* GetFrame(int index, float now); RECT* GetFrame(int index);bool Start(int index);bool Reset(int index);void Stop(int index);bool Check(int index);void Update(int index, float now);void SetFrame(int index, int frame);RECT* LoopAnimation(int index, float now); //If an end tag is throw we just continue to runvoid Save(std::ofstream &file);void Load(std::ifstream &file);};struct cPhysData{ //Physical Datafloat rotation; //A floating point representation of RotationcVector2 scale; //A vector representation of scalecVector2 position; //A vector representation of positioncVector2 center;void Save(std::ofstream &file);void Load(std::ifstream &file);cPhysData();~cPhysData();cPhysData(const cPhysData &rhs);void operator=(const cPhysData &rhs);};struct cObject{cObject();cObject(const cObject &rhs);void operator=(const cObject &rhs);~cObject();std::string m_texture; //Character StringcPhysData m_phys; //PhysdatacAnimation2d m_anim;int m_index;}; //A graphical and physical game objectAnd I realized that it is very strangely structure, inefficient, whathave you. Make it work, Make it fast, Make it Pretty.Anyway, if you want the renderer code or anything, I'll be happy to put anything else up as well.For the record it all properly loads from the file, and then decides it would like to commit suicide.[Edited by - Plasmarobo on June 10, 2009 5:55:10 PM]