Sign in to follow this  

Breakpoints override program crash

This topic is 3108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 out because 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'm revamping it, to get rid of this kind of stuff). This problem has me completely floored, and I just wondered if anyone had ever run into something like this, and could give me a few pointers about where to look. 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 pass of 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't effect 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.

Share this post


Link to post
Share on other sites

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 values
if(!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 text
std::vector<cText>::iterator titer;
for(titer = m_tbatch.begin(); titer != m_tbatch.end(); ++titer)
{
//TODO, CUSTOM TEXT-DRAWING
m_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 position
float 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 animation
unsigned long size; //This is the size of the animation
//Engine vars
float last;
int index;
//bool loop; //Looping trigger
public:
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 datas
unsigned 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 run



void Save(std::ofstream &file);

void Load(std::ifstream &file);

};

struct cPhysData
{ //Physical Data
float rotation; //A floating point representation of Rotation
cVector2 scale; //A vector representation of scale
cVector2 position; //A vector representation of position
cVector2 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 String
cPhysData m_phys; //Physdata
cAnimation2d m_anim;
int m_index;
}; //A graphical and physical game object




And 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]

Share this post


Link to post
Share on other sites

This topic is 3108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this