Sign in to follow this  
chbrules

[SDL/C++] My Scene Manager Crashes My Game When Creating New Object

Recommended Posts

chbrules    170
So I decided it'd be handy to impliment a scene manager for my game engine I'm working on. I've debugged everything to death so far, and everything else seems great, but I've stumbled upon one thing that crashes my game. My scene manager crashes when I try to allocate a new instance of my 'Game' scene to the manager's scene pointer. I've created a base class (CScene) which each scene inherits, this way I can use the base class datatype as a pointer for all the derived scene classes. Here's what my ChangeScene(int) function does:
//Tells the system which scene's render and loop sequence to use
void CSManager::ChangeScene(UInt16 Scene)
{
	if(pScene != NULL){ delete pScene; }
	Current_Scene = Scene;

	switch(Current_Scene)
	{
	case 0:
		{
			pScene = new CLoading;
			break;
		}
	case 1:
		{
			pScene = new CMenu;
			break;
		}
	case 2:
		{
			pScene = new CGame(".\\maps\\Neon.nmf");
			break;
		}
	case 3:
		{
			pScene = new CScore;
			break;
		}
	};
}
I default the current scene to '2' so it'll load right into the game scene for now. Everything goes great until I try to create a new instance of CGame. I get a weird runtime error:
Debug Assertion Failed!

Program: ...Neon.exe
File: dbgdel.cpp
Line: 52

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
Just in case it makes any difference, here's CGame's constructor:
CGame::CGame(string strFile)
{
	screen = SDL_GetVideoSurface();
	Load->LoadMap(strFile, Header, Param, Map, TextureList, author, map_name);
	Load->LoadTextures(TextureList, Textures);
}
All the code inside seems to work fine as CGame is being initialized and whatnot, but when it the constructor gets done, back in the scene manager, it crashes when it tries to assign pScene the pointer value of the new CGame object. I've limited my code to only do that from when main() starts right into the manager after initializing SDL and the window. So nothing else is happening but that. Any idea? :( Thanks a million guys!

Share this post


Link to post
Share on other sites

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