Skip to content

Commit

Permalink
Fix deep in game crash when using RegisterInputListener from an observer
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamashi committed Aug 20, 2021
1 parent b0ca824 commit 1db1b17
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/scripting/FunctionOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "FunctionOverride.h"
#include "Scripting.h"
#include <reverse/StrongReference.h>


static FunctionOverride* s_pOverride = nullptr;
Expand Down Expand Up @@ -35,13 +36,13 @@ bool FunctionOverride::HookRunPureScriptFunction(RED4ext::CClassFunction* apFunc

auto state = itor->second.pScripting->GetState();

if (apContext->context18)
auto pContext = apContext->GetContext();
if (pContext)
{
RED4ext::CStackType self;
self.type = reinterpret_cast<RED4ext::IScriptable*>(apContext->context18)->classType;
self.value = apContext->context18;
const auto handle = RED4ext::Handle<RED4ext::IScriptable>(pContext);
auto obj = sol::make_object(state.Get(), StrongReference(state, handle));

args.push_back(Scripting::ToLua(state, self));
args.push_back(obj);
}

for (auto* p : apFunction->params)
Expand Down Expand Up @@ -208,7 +209,7 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,
}
else
{
self.type = ((RED4ext::IScriptable*)apFrame->context)->classType;
self.type = apFrame->context->classType;
self.value = apFrame->context;
}

Expand All @@ -222,7 +223,10 @@ void FunctionOverride::HandleOverridenFunction(RED4ext::IScriptable* apContext,

auto state = context.pScripting->GetState();

args.push_back(Scripting::ToLua(state, self)); // Push self
const auto handle = RED4ext::Handle<RED4ext::IScriptable>((RED4ext::IScriptable*)self.value);
auto obj = sol::make_object(state.Get(), StrongReference(state, handle));

args.push_back(obj);

// Nasty way of popping all args
for (auto& pArg : apFunction->params)
Expand Down

0 comments on commit 1db1b17

Please sign in to comment.