🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Problem with default arguments

Started by
13 comments, last by WitchLord 9 years, 5 months ago

I have a problem with this method:


void CASGame::ClientPrintAll( int iMsgDest, const CASString& szMsgName, 
					const CASString& szParam1, const CASString& szParam2, const CASString& szParam3, const CASString& szParam4 )

CASString is a string class, which only stores a pointer to a char*.

This function is exposed as:


"void ClientPrintAll(HUD iMsgDest, const string& in szMessage, const string& in szLine2 = \"\", "
		"const string& in szLine3 = \"\", const string& in szLine4 = \"\", const string& in szLine5 = \"\")"

Where HUD is an enum.

The function is called like this:


g_Game.ClientPrintAll( HUD_PRINTNOTIFY, "Changing map" );

Where g_Game is an instance of CGame, and HUD_PRINTNOTIFY is one of the HUD values.

For some reason, the last 2 strings are empty. Not empty as in pointing to a string ""; the pointer itself is NULL. The string class is written in such a way that this can never happen, which means that something else must be wrong.

The calling convention is correct, and i can't see what else could possibly be wrong.

Advertisement

After further testing i have determined that the strings are only null if the method is called like this:


void test()
{
    g_Game.ClientPrintAll( HUD_PRINTNOTIFY, "abc" + "test" );
}

In this case, the last parameter is null, but if another addition occurs, the second to last parameter is also null.

It seems that for every addition that occurs, one more default parameter is not initialized.

Looks like a bug in the AngelScript compiler.

What version of AngelScript are you using?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I'm using version 2.29.2.

Unfortunately I haven't been able to reproduce this problem.

Can you show me how you've registered your string type?

Also, would you mind giving the latest WIP version from the svn a try? It might be that the problem has already been fixed in another change I made.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This is the registration of the entire string class: http://pastebin.com/iStrQEhi

RegisterSCScriptForwardDeclareString is called first to register the type, after that RegisterSCScriptASString is called to register the remainder.

CASDocumentation forwards all registration calls and handles the result, so nothing special goes on there.

REGISTER_VARARGS_FUNCTION is a macro that registers overloads for a function that accepts ?& in types.

I'll see if i can get the latest version up and running in our codebase.

Thanks for sharing. Unfortunately I still can't reproduce the problem.

I don't see anything wrong with your code either, so I suspect this was likely a bug in version 2.29.2, that has been fixed in one of the many changes already done for 2.30.0 WIP.

Let me know if you have any restrictions to upgrade to 2.30.0 WIP. If so I'll investigate the 2.29.2 code base.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've upgraded to 2.30.0 WIP; the problem still occurs. Since you have been unable to reproduce the issue, i suspect the problem is somewhere in my string class, but so far i haven't seen any problems.

Would you be able to reproduce it in a small piece of code that you can share with me so I can debug it?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I'll set up the string class in a self contained program and see if the problem occurs there.

This topic is closed to new replies.

Advertisement