Fix crash on Clang-platforms when calling base method from overriden scripting method (C# or Visual Script)

This commit is contained in:
Wojtek Figat
2022-12-28 16:28:50 +01:00
parent 320c8481e6
commit 3a393b6825
3 changed files with 66 additions and 27 deletions

View File

@@ -7,6 +7,30 @@
#include "ScriptingType.h"
#include "Types.h"
#if defined(__clang__)
// Helper utility to override vtable entry with automatic restore
// See BindingsGenerator.Cpp.cs that generates virtuall method wrappers for scripting to properly call overriden base method
struct FLAXENGINE_API VTableFunctionInjector
{
void** VTableAddr;
void* OriginalValue;
VTableFunctionInjector(void* object, void* originalFunc, void* func)
{
void** vtable = *(void***)object;
const int32 vtableIndex = GetVTableIndex(vtable, 200, originalFunc);
VTableAddr = vtable + vtableIndex;
OriginalValue = *VTableAddr;
*VTableAddr = func;
}
~VTableFunctionInjector()
{
*VTableAddr = OriginalValue;
}
};
#endif
#if USE_MONO
extern "C" FLAXENGINE_API void mono_add_internal_call(const char* name, const void* method);