I have a derived class from a base class registered as in the template example. If I call a base class method, everything is fine. If I call a method of the derived class I get a SEGV in the Wrappers.
I am on (Ubuntu/ARM64 using generic wrappers)
In the leadup to Execute() I create a script on the fly that looks like:
std::string script = "DerivedClass m4808(5,0);int cowboy(){ m4808.setRPM(10); Print(\"CC Command sent\r\n\"); return 0; }"
The sequence of preparing the module is:
// Get/Create the module, add the script and build/compile
asIScriptModule* seMod = gSE.getEngine().GetModule(SE_COWBOY_MODULE, asGM_ALWAYS_CREATE); assert(seMod != nullptr);
if (seMod->AddScriptSection(SE_COWBOY_SECTION, script.c_str()) < 0)
{
LOG_F(WARNING, "Unable to add script section: %s", SE_COWBOY_SECTION);
return; //seStatus::ERROR_FUNCTION_NOT_FOUND;
}
if (seMod->Build() < 0)
{
LOG_F(WARNING, "Unable to build module: %s", SE_COWBOY_MODULE);
return; // seStatus::ERROR_FUNCTION_NOT_FOUND;
}
if (m_pMainCtx->Prepare(gSE.getEngine().GetModule(SE_COWBOY_MODULE)->GetFunctionByDecl(SE_COWBOY_FUNCTION)) < 0)
{
LOG_F(WARNING, "Unable to prepare script function: %s", SE_COWBOY_MODULE);
return; // seStatus::ERROR_FUNCTION_NOT_FOUND;
}
// execute the script
if (m_pMainCtx->Execute() == asEXECUTION_FINISHED)
{ … }
The application SEGVs during the Execute() with
Thread
3 "ScriptEngine" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fb6b1ed60 (LWP 1777)]
gw::Wrapper<MotorStatus (DerivedClass::*)(double, double, short, short)>::f<&amp;DerivedClass::setRPM> (gen=0x7fb6b1d690) at ../include/as_add_on/autowrapper/aswrappedcall.h:456
456 new (gen->GetAddressOfReturnLocation()) Proxy<R>((static_cast<T *>(gen->GetObject())->*fp)(
and the aswrappedcall is:
(In the template, gen* is not null, but A0, A1, A2, A3 look like garbage)
template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
struct Wrapper<R (T::*)(A0, A1, A2, A3)> {
template <R (T::*fp)(A0, A1, A2, A3)>
static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) {
new (gen->GetAddressOfReturnLocation()) Proxy<R>((static_cast<T *>(gen->GetObject())->*fp)(
static_cast<Proxy <A0> *>(gen->GetAddressOfArg(0))->value,
static_cast<Proxy <A1> *>(gen->GetAddressOfArg(1))->value,
static_cast<Proxy <A2> *>(gen->GetAddressOfArg(2))->value,
static_cast<Proxy <A3> *>(gen->GetAddressOfArg(3))->value));
}
};