Archive 17/01/2023.

[SOLVED] Possible bug in AngelScript - interface

Sasha7b9o

Hi.
When I call function CScriptArray VectorToArray(const Vector& vector, const char arrayName)** (VectorToArray <String> (GetArguments(), "Array<String>");),
linker write error “can not find funciton asGetActiveContext();” (Urho3D compiled with option -DURHO3D_LIB_TYPE=SHARED)
If link library ActionScript.lib manually, game compiles, but function asGetActiveContext() return 0. In comments function write:

// tld can be 0 if asGetActiveContext is called before any engine has been created.

// Observe! I've seen a case where an application linked with the library twice
// and thus ended up with two separate instances of the code and global variables.
// The application somehow mixed the two instances so that a function called from
// a script ended up calling asGetActiveContext from the other instance that had
// never been initialized.

When engine compiled with option DURHO3D_LIB_TYPE=STATIC , everything is fine.

Sorry for bad english

weitjong

Something like this has been discussed before, but I cannot remember where. This is the drawback (or benefit, depending on how you see it) of using SHARED lib type because the library target is produced by invoking a linking phase which does a dead code elimination. That is, all symbols not referenced directly or indirectly by Urho itself are being eliminated. Note that in our current setup, the internal 3rd-party libs are always statically linked regardless of Urho3D lib type chosen.

There are a few ways to workaround this. Two that do not require modifications to the engine code and build system would be:

  • Using Urho3D STATIC lib, which is basically just an archive of all symbols there are (like you have pointed out); Or
  • Add a new SHARED lib target in your own project that statically linked to Urho3D lib, which references the symbols you want from AngelScript lib. Then make your app depends on your new SHARED lib target.
Sasha7b9o

Thanks. But this method does not work, or I misunderstood. Could you explain in more detail?

cadaver

This particular case looks like that there should be a Urho3D wrapper for asGetActiveContext() which should be used by the template functions so that it would work for both cases.

weitjong

I didn’t look at the code yet so far. But yes, I think so. If it is referenced somewhere then the symbol would be kept.

cadaver

In master branch, template functions no longer call asGetActiveContext() directly.

Sasha7b9o

Very nice.
Now everything works as it should)