Sign in to follow this  
Gumgo

Release mode NOT working right!! *solved

Recommended Posts

I've got a weird problem with release mode not working. It has to do with reading from script files. Get ready for a fair amount of code...
void ScriptClass::ExecuteScript( int id ) // this is for executing scripts
{
	bool keepreading = true;
	int Line = 0;
	byte result;
	std::string LineData;
	std::string LineFunction;
	std::string LineValue;
	std::ifstream * file;
	size_t pos;

	std::map<int, std::ifstream*>::iterator iter;
	iter = Script_Container.find( id );
	file = iter->second;
	file->clear();
	file->seekg( 0 );

	// the guts of it... uuuugh

	while (!file->eof() && keepreading)
	{
		Line++;
		std::getline( *file, LineData );
		if (LineData == "")
			continue;
		pos = LineData.find(";");
		if (pos == 0)
			continue;
		pos = LineData.find( ":" );
		if (pos == std::string::npos  || pos == 0)
		{
			SyntaxError( Line, LineData );
			continue;
		}

		result = ExecuteCommand( LineData, Line, pos, file );
		switch (result)
		{
			case 1: // end
				keepreading = false;
				break;
			case 2: // read until end of file, or until "End:"
				while (!file->eof() && LineData != "End:")
				{
					Line++;
					std::getline( *file, LineData );
				}
		}
	}
}

...

byte ScriptClass::ExecuteCommand( std::string linedata, int line, size_t sepPos, std::ifstream * file )
{
//////////////////////////////////////////////////////////////// stuff used in most functions
	bool valid = false;
	std::map<std::string, CommandList>::iterator iter;
	int id;
	unsigned int pos;
	int file_position; // for functions, keep current position
	Obj2DClass * obj2dhold;
	ButtonClass * btnhold;
	TextureClass * texhold, *texhold2, *texhold3;
	TextClass * texthold;
	std::string shortstr, param1, param2, param3, param4, param5, param6, param7;

	std::istringstream stream_i;
//////////////////////////////////////////////////////////////// now the real stuff
	std::string LineFunction = linedata.substr( 0, sepPos );
	std::string LineValue = linedata.substr( sepPos + 1, std::string::npos );

	for (iter = Command_Container.begin(); iter != Command_Container.end(); iter++)
	{
		if (LineFunction == iter->first)
		{
			valid = true;
			break;
		}
	}
	if (valid == false)
	{
		SyntaxError( line, linedata );
		return 0;
	}

	switch (Command_Container[LineFunction])
	{
... about 50 miles later ...
	case BgCreate: // creates a background
		pos = 0;
		param1 = "";
		param2 = "";
		param3 = "";
		param4 = "";
		param5 = "";
		while (pos <= LineValue.length() && LineValue.at(pos) != '|')
		{
			param1 += LineValue[pos];
			pos++;
		}
		pos++;
		while (pos <= LineValue.length() && LineValue.at(pos) != '|')
		{
			param2 += LineValue[pos];
			pos++;
		}
		pos++;
		while (pos <= LineValue.length() && LineValue.at(pos) != '|')
		{
			param3 += LineValue[pos];
			pos++;
		}
		pos++;
		while (pos <= LineValue.length() && LineValue.at(pos) != '|')
		{
			param4 += LineValue[pos];
			pos++;
		}
		pos++;
		while (pos <= LineValue.length())
		{
			param5 += LineValue[pos];
			pos++;
		}
		id = StringToInt( param1 );
		texhold = ObjContainer->GetTexture( id );
		id = StringToInt( param5 );
		obj2dhold = ObjContainer->AddBackground( id );
		obj2dhold->Init( texhold, NULL, StringToDbl( param2 ), StringToDbl( param3 ), StringToInt( param4 ), 0, 1, 1, 0, 0, 1 );
		obj2dhold->ScriptAccess = this;

		GLoop->AddObj( obj2dhold );
		Render2D->AddObj( obj2dhold );
		CleanUp->AddObj( obj2dhold );
		return 0;
	case BgDelete:
		id = StringToInt( LineValue );
		obj2dhold = ObjContainer->GetBackground( id );
		obj2dhold->DEL_ME = true;
		return 0;
... 50 more miles of code ...
	}
}

... in another far off distant file ...

Obj2DClass* ObjectContainerClass::AddBackground( int id )
{
	Obj2DClass * tx = new Obj2DClass;
	Background_Container.insert( std::pair<int, Obj2DClass*>( id, tx ) );
	return (tx);
}

Obj2DClass* ObjectContainerClass::GetBackground( int id )
{
	std::map<int, Obj2DClass*>::iterator iter;
	iter = Background_Container.find( id );
	return iter->second;
}




And here's the script file:
FuncSet:LOAD_MENU_BACKGROUNDS

TexLoad:Data\Menu\Menu1.bmp|1
TexLoad:Data\Menu\Menu2.bmp|2
...
TexLoad:Data\Menu\Back.bmp|7
TexLoad:Data\Menu\BackMask.bmp|8

BgCreate:1|0|0|0|1
BgCreate:2|256|0|0|2
BgCreate:3|512|0|0|3
BgCreate:4|0|256|0|4
BgCreate:5|256|256|0|5
BgCreate:6|512|256|0|6

BgCreate:7|320|240|1|7


BgModify:1|8|0|7
BgModify:7|128|0|7
BgModify:8|128|0|7

End:

...

FuncSet:UNLOAD_MENU_BACKGROUNDS

TexFree:1
TexFree:2
...
TexFree:6
TexFree:7

BgDelete:1
BgDelete:2
BgDelete:3
BgDelete:4
BgDelete:5
BgDelete:6
BgDelete:7

End:
Now the weird problem... Everything works as it should in debug mode (when I execute this script): it loads the textures and creates the backgrounds. BUT In release mode, for SOME reason, it does not create the backgrounds (BgCreate's last parameter is the ID) #1, 2, 3, and 4. Actually, it just doesn't create whichever first 4 are listed. I have NO idea why this is. And the weird thing is, I have code to load and delete backgrounds before this and it works fine. Anyways, I don't really know how much to post for it to be "enough info" so if you need ANY more info to help solve this problem just tell me, I'd be glad to post anything that helps. I think from now on I'm going to test release mode more frequently... Here's a few things I know: The size of the background container DOES increase when I add the background (it does get added, that seems to indicate). [Edited by - Gumgo on May 24, 2007 2:09:56 AM]

Share this post


Link to post
Share on other sites
usually, atleast with my release issues. It comes from not initalizing variables.

Scan through and make sure you initing everything before tinkering around with it...could be bad data

... if that wasn't clear, make sure you init everything in your constructors...I know i've had my fair share of these issues

Share this post


Link to post
Share on other sites
Ugh... I didn't know that... I think I have a fair amount of uninitialized variables in there. I'll go through and check.

EDIT: Yay! That was the problem! :D Turned out I had ONE uninitialized variable that was derived, and it had to do with deleting the object (which as you can guess... deleted the object when it was created!)

You saved me what probably would be hours of trying to find the problem, thanks a ton rating++

[Edited by - Gumgo on May 24, 2007 12:22:45 AM]

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