Jump to content
  • Advertisement
stalker#3829

AngelScript 2.33.1: Bugs && Features

Recommended Posts

Hi!
Didn't found info how/where to report bugs, so going to share some findings on the forum. Btw what's the proper way to report bugs?

I'm trying to use AngelScript in my pet project, for now getting familiar with AS.

Using AngelScript 2.33.1 (50229f5 github commit), Linux x86-64, gcc 8.3.0.

1) AddressSanitizer: heap-buffer-overflow. (+-1 byte error)
AddressSanitizer detects read of unallocated memory at line (strcmp compares null-terminated strings)
The memory allocated here is not correct when "in_length = strlen(in_code);", strlen doesn't count null-char.

Fix that works for me:

code = asNEWARRAY(char, in_length + 1);
    if( code == 0 )
        return asOUT_OF_MEMORY;
memcpy(code, in_code, in_length);
code[in_length] = '\0';

But if this part of AS works only with null-terminated strings than maybe strcpy (deals with null-char) should replace memcpy?


2) asMETHOD with method of a base class.
asMETHOD doesn't detect ptrdiff_t for member function of base class, it's always 0. Workaround is to abuse asMETHODPR as much as possible.
Attached online_gcc_8.cpp example (compatible with http://cpp.sh/)

online_gcc_8.cpp

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

Additional info/question. My pet project is an AI for Zero-K RTS game.
Does anyone have successful experience with AS 2.33.1 + JIT (BlindMind's / bluecataudio's) + AATC (Angelscript addon Template Containers), any hints about how to setup/use collection of those tools (linux64+gcc preferably) and possible pitfalls? (by hints i think of "avoid noob-trap asMETHOD, use asMETHODPR", etc.)

Edited by stalker#3829

Share this post


Link to post
Share on other sites

Thanks for the bug report. Here is the right place for this. Alternatively you can send the bug report directly to me by e-mail.

I'll look into this and the suggestion for the asMETHOD macro too.

Unfortunately I cannot help you much with the other tools.

Regards,

Andreas

Share this post


Link to post
Share on other sites
Posted (edited)

Another confusion with multiple inheritance: baseOffset not applied to auxiliary object.

Here's an example (stub):

...
// C++ part
    class A {
    public:
        int SomeWorkA(int a) {
            printf("A::SomeWorkA | %lx | %i\n", this, aa);
            return a;
        }
        int aa = 33;
    };
    class B {
    public:
        int SomeWorkB(int b) {
            printf("B::SomeWorkB | %lx | %i\n", this, bb);
            return b;
        }
        int bb = 44;
    };

    class C: public A, public B {
    };

    C* c = new C;  // enough for the purpose of example

    c->SomeWorkA(0);  // prints A::SomeWorkA | 5555d132e3e0 | 33
    c->SomeWorkB(0);  // prints B::SomeWorkB | 5555d132e3e4 | 44

#if 1
    r = engine->RegisterGlobalFunction("int someWork(int)", asMETHODPR(C, SomeWorkB, (int), int), asCALL_THISCALL_ASGLOBAL,
			c); assert(r >= 0);
#else
    r = engine->RegisterGlobalFunction("int someWork(int)", asMETHODPR(C, SomeWorkB, (int), int), asCALL_THISCALL_ASGLOBAL,
			(B*)c); assert(r >= 0);
#endif
...
// script part
    someWork(0);
...

And the output:

r = engine->RegisterGlobalFunction(..., c);
A::SomeWorkA | 5555d132e3e0 | 33
B::SomeWorkB | 5555d132e3e4 | 44
calling someWork(0) from script:
B::SomeWorkB | 5555d132e3e0 | 33
r = engine->RegisterGlobalFunction(..., (B*)c);
A::SomeWorkA | 5555d1320350 | 33
B::SomeWorkB | 5555d1320354 | 44
calling someWork(0) from script:
B::SomeWorkB | 5555d1320354 | 44

So for correct execution the class should be explicitly casted to the correct base one during global function registration, which was not clear to me and may be a bug (baseOffset not applied to auxiliary object).


Sidenote: I've managed to setup AS+JIT+AATC. AATC uses reference counters through multiple inheritance. BlindMind's JIT also has bug with methods from multiple inheritance: doesn't apply baseOffset with gcc, but that's another topic.

Edited by stalker#3829

Share this post


Link to post
Share on other sites

Thanks, I'll look into this one too.

It will take a while though. I'm short on time and in order to work on this problem I'll need to recreate my Linux environment, which unfortunately got corrupted some time back.

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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!