Advertisement

AngelScript 2.33.1: Bugs && Features

Started by April 23, 2019 01:12 PM
6 comments, last by WitchLord 5 years, 5 months ago

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

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.)

Advertisement

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

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

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.

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.

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 fixed the first memory issue in revision 2580.

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

I've fixed the problem with multiple inheritance ans asCALL_THISCALL_ASGLOBAL in revision 2595.

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