Jump to content
  • Advertisement
Sign in to follow this  

SomeThing Strange! Maybe a Bug

This topic is 3992 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 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 &in 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]

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!