Fix crash when Visual Script event binding instance is invalid

#2548
This commit is contained in:
Wojtek Figat
2024-05-09 10:17:23 +02:00
parent f353d3f114
commit 5029584a9f

View File

@@ -886,7 +886,8 @@ void VisualScriptExecutor::ProcessGroupFunction(Box* boxBase, Node* node, Value&
instance = eatBox(node, box->FirstConnection()); instance = eatBox(node, box->FirstConnection());
else else
instance.SetObject(object); instance.SetObject(object);
if (!instance.AsObject) ScriptingObject* instanceObj = (ScriptingObject*)instance;
if (!instanceObj)
{ {
LOG(Error, "Cannot bind event to null object."); LOG(Error, "Cannot bind event to null object.");
PrintStack(LogType::Error); PrintStack(LogType::Error);
@@ -928,13 +929,13 @@ void VisualScriptExecutor::ProcessGroupFunction(Box* boxBase, Node* node, Value&
} }
eventBinding->BindedMethods.Add(method); eventBinding->BindedMethods.Add(method);
if (eventBinding->BindedMethods.Count() == 1) if (eventBinding->BindedMethods.Count() == 1)
(*eventBinder)(instance.AsObject, object, true); (*eventBinder)(instanceObj, object, true);
} }
else if (eventBinding) else if (eventBinding)
{ {
// Unbind from the event // Unbind from the event
if (eventBinding->BindedMethods.Count() == 1) if (eventBinding->BindedMethods.Count() == 1)
(*eventBinder)(instance.AsObject, object, false); (*eventBinder)(instanceObj, object, false);
eventBinding->BindedMethods.Remove(method); eventBinding->BindedMethods.Remove(method);
} }
} }