Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


problem with stl stack

This topic is 5321 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 am using the stl stack for my games state manager and my game keeps crashing. Here is the code for my state manager, and then I will further explain the problem.

#include <stack>
using namespace std;

class Cstate
	bool SetDevices(CinputDevice *kb, Cgraphics *gfx);

	virtual bool Init() {return true;}
	virtual bool Shutdown() {return true;}
	virtual bool Frame() {return true;}

	CinputDevice *keyboard;


	Cgraphics *graphics;

class CstateManager
	bool Push(Cstate *state);
	bool Pop();

	bool Init();
	bool Shutdown();
	bool Frame();

	int GetNStates();
	Cstate *GetTop();

	stack<Cstate *> stateStack;

bool CstateManager::Frame()
	return stateStack.top()->Frame();

//set up states

CstateManager stateManager; //state manager


CmenuState mainMenuState;

mainMenuState.SetDevices(&keyboard, &graphics);
//set up the state manager


CmenuState is derived from Cstate It crashes when I call stateManager.Frame(). And it says unhandled exception... access violation reading location 0x00000000. It breaks on this line, return stateStack.top()->Frame();. Does anyone know what the problem is. Also this is my first attempt at a state manager, and im not really sure if i did a very good job on it, does anyone have some suggestions for it.

Share this post

Link to post
Share on other sites
When do you call CstateManager::Frame()? Is it possible that Frame() is being called before you push anything on the stack?

Share this post

Link to post
Share on other sites
Ok i checked it out, and the state is not NULL before it gets pushed onto the stack, but once on the stack it is showing that stack.top() = NULL. what is going on.

Share this post

Link to post
Share on other sites
What does the CstateManager::Push() function look like?

edit: !@#$! smiley code

[edited by - SiCrane on February 27, 2004 11:56:30 PM]

Share this post

Link to post
Share on other sites
if (state = NULL)

should be

if (state == NULL)

You''re assigning NULL to state instead of checking state against NULL. Probably a sign that you''re compiling with the warning level too low.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!