Skip to main content
gamedev.net
🔒 Locked

Odd Error.

Started by Daishim 2 replies 250+ views
Original Post
Daishim
Daishim
I have a class CHARACTER that is part of another class GAME. When I put the CHARACTER class in, my game will generate an exception error upon exiting (after return 0 from the WinMain). When I take it out my game will exit properly. My class...
enum CHARACTER_DIRECTION {CD_LEFT, CD_UP, CD_RIGHT, CD_DOWN};

class CHARACTER
{
	GAMERECT CharacterRect;
	GAMERECT CharacterSourceRect[4];

	int AnimationPosition;

	CHARACTER_DIRECTION Direction;

	public:
		CHARACTER();
		~CHARACTER();

		GAMERECT GetCharacterRect();
		void SetCharacterRect(GAMERECT NewRect);

		GAMERECT GetCharacterSourceRect();
		void SetCharacterSourceRect(GAMERECT NewRect);

		CHARACTER_DIRECTION GetDirection();
		void SetDirection(CHARACTER_DIRECTION NewDirection);

		bool Initialize(STRING FileName);

};

// Character constructor, initializes the character object

CHARACTER::CHARACTER()
{
	CharacterRect.Left = 0;
	CharacterRect.Width = 1;
	CharacterRect.Top = 0;
	CharacterRect.Height = 1;

	for(int i = 0; i < 20; i++)
	{
		CharacterSourceRect[i].Left = 0;
		CharacterSourceRect[i].Width = 0;
		CharacterSourceRect[i].Top = 0;
		CharacterSourceRect[i].Height = 0;

	}

	Direction = CD_RIGHT;

}

// Character destructor, uninitializes any intialized objects when destroyed

CHARACTER::~CHARACTER()
{
	MessageBox(NULL, "Test", "Test", MB_OK);

}

// Returns the Character position as GAMERECT

GAMERECT CHARACTER::GetCharacterRect()
{
	return CharacterRect;

}

// Sets the character rect with that passed in

void CHARACTER::SetCharacterRect(GAMERECT NewRect)
{
	CharacterRect = NewRect;

}

// Returns the character position as GAMERECT

GAMERECT CHARACTER::GetCharacterSourceRect()
{
	GAMERECT ReturnRect;

	switch(Direction)
	{
		case CD_UP:
			{
				ReturnRect = CharacterSourceRect[0];

				break;

			}

		case CD_RIGHT:
			{
				ReturnRect = CharacterSourceRect[1];

				break;

			}

		case CD_DOWN:
			{
				ReturnRect = CharacterSourceRect[2];

				break;

			}

		case CD_LEFT:
			{
				ReturnRect = CharacterSourceRect[3];

				break;

			}

		default:
			{
				ReturnRect = CharacterSourceRect[0];

				break;

			}

	}

	return ReturnRect;

}

// Sets the character source rect with that passed in

void CHARACTER::SetCharacterSourceRect(GAMERECT NewRect)
{
	CharacterSourceRect[0] = NewRect;

}

// Returns the direction that the character is currently facing

CHARACTER_DIRECTION CHARACTER::GetDirection()
{
	return Direction;

}

// Sets the characters current direction

void CHARACTER::SetDirection(CHARACTER_DIRECTION NewDirection)
{
	Direction = NewDirection;

}

// Initializes the character data from the file passed in

bool CHARACTER::Initialize(STRING FileName)
{
	GAMERECT TempRect;

	ifstream fin(FileName.GetString(), ios::binary);

	if(!fin)
	{
		return false;

	}

	fin.read((char *) &CharacterRect.Width, sizeof(CharacterRect.Width));
	fin.read((char *) &CharacterRect.Height, sizeof(CharacterRect.Height));

	for(int i = 0; i < 4; i++)
	{
		fin.read((char *) &TempRect, sizeof(TempRect));

		CharacterSourceRect[i] = TempRect;

	}

	fin.close();

	return true;

}
There isn''t anything that is coming to my attention that could be wrong with this class, it compiles and runs fine, just unloading it creates an error. There is no pointer to it, it''s in the my GAME class an object itself. I''m really at a loss... any ideas?

I know only that which I know, but I do not know what I know.

I know only that which I know, but I do not know what I know.
SiCrane
SiCrane
Do you still get the error if you remove the MessageBox() call from the destructor?
Daishim
Daishim
Yes.



I know only that which I know, but I do not know what I know.

I know only that which I know, but I do not know what I know.
Daishim
Daishim
I fixed it. It turned out that I was over running the array of source RECTs in the Constructor.



I know only that which I know, but I do not know what I know.

I know only that which I know, but I do not know what I know.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.