Advertisement

SomeThing Strange! Maybe a Bug

Started by June 14, 2007 12:40 AM
3 comments, last by WitchLord 17 years, 5 months ago
I use 2.8.0a uint8 test2() { int i; i += 3; return 3; } uint8 test(uint8 port) { test2(); GlobalCharArray[1] = port; PRINTS(HEX0(GlobalCharArray[1])); return port; } main() { test(0x30); } it will print "0x01" not "0x30" ps: GlobalCharArray is a global uint8[] I create it with GlobalCharArray =(asIScriptArray*)engine->CreateScriptObject(engine->GetTypeIdByDecl(0, "uint8[]")); GlobalCharArray->Resize(256); r = engine->RegisterGlobalProperty("uint8[] GlobalCharArray", GlobalCharArray); assert( r >= 0 ); ==================== 1. If I replace "uint8 test2()" ===> "void test2()", the result is "0x30" 2. If I replace "uint8 test(uint8 port)" with "uint8 test(const uint8 port), the result is "0x30" 3. as 2, I replace "uint8 test(uint8 port)" with "uint8 test(uint8 ∈ port)" the result is "0x30" 4. If I just replace GlobalCharArray[1] with GlobalCharArray[5], then the result is "0x05" 5. If I reorder the codes like that: GlobalCharArray[1] = port; test2(); PRINTS(HEX0(GlobalCharArray[1])); the result is "0x30" It seems a Bug of AngelScript! [Edited by - loboWu on June 14, 2007 1:07:17 AM]
Interesting. It does indeed look like a bug in AS, and a strange one at that. I'll look into it.

There's been a lot of bug fixes for 2.8.1 WIP, would you mind giving the latest version in SVN a try (currently revision 152) to see if your problem remains in the new version?

Regards,
Andreas

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

Advertisement
For what it is worth, I tested this on the latest code in SVN and it worked as expected (printed out 0x30).

Here is the code I used:
static const char *script ="uint8 test2() \n""{             \n""	int i;     \n""	i += 3;    \n""	return 3;  \n""}             \n""uint8 test(uint8 port)               \n""{                                    \n""	test2();                          \n""	GlobalCharArray[1] = port;        \n""	PRINTS(HEX0(GlobalCharArray[1])); \n""	return port;                      \n""}                                    \n""void main()    \n""{              \n""	test(0x30); \n""}              \n";asCScriptString *HexPrint(unsigned char v){	char buffer[8];	sprintf( buffer, "0x%02X", v );	return new asCScriptString( buffer );}void PrintString( asCScriptString *str ){	printf( "%s\n", str->buffer.c_str() );}void Test(){	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);	RegisterScriptString( engine );	asIScriptArray *GlobalCharArray;	GlobalCharArray =(asIScriptArray*)engine->CreateScriptObject(engine->GetTypeIdByDecl(0, "uint8[]"));	GlobalCharArray->Resize(256);	int r;	r = engine->RegisterGlobalProperty("uint8[] GlobalCharArray", GlobalCharArray); assert( r >= 0 );	r = engine->RegisterGlobalFunction("string &HEX0(uint8)", asFUNCTION(HexPrint), asCALL_CDECL); assert( r >= 0 );	r = engine->RegisterGlobalFunction("void PRINTS(const string &in)", asFUNCTION(PrintString), asCALL_CDECL); assert( r >= 0 );	r = engine->AddScriptSection( 0, 0, script, strlen(script) ); assert( r >= 0 );	r = engine->Build(0); assert( r >= 0 );		r = engine->ExecuteString(0,"main();"); assert( r >= 0 );	GlobalCharArray->Release();	engine->Release();	engine = NULL;}
I use the latest version from SVN.
The result are all "0x30" in my testing environment.
Thanks a lot
Excellent! Thanks for confirming that for me.

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 topic is closed to new replies.

Advertisement