fix(Lua): Correctly handle non-container Out-params in function calls #942
+3
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical bug in the Lua scripting backend that caused stack corruption when calling a UFunction with an
Outparameter that was not aFStructPropertyorFArrayProperty.The Problem:
The internal function
call_ufunction_from_luacorrectly identifiesOutparameters and expects a placeholder Lua table on the stack. However, forOutparameters that are simple object pointers (e.g.,UObject*&), the logic wouldcontinueto the next parameter without popping the placeholder table from the Lua stack.This desynchronized the stack, causing subsequent parameters to be read incorrectly and leading to a crash.
The Solution:
A single line,
lua.discard_value(), has been added to the conditional block that handles theseOutparameters. This ensures the placeholder table is correctly removed from the stack, restoring proper argument processing.Type of change
How has this been tested?
The fix was tested on UE4SS build
zDEV-UE4SS_v3.0.1-442-gfb22cb3against a game running on Unreal Engine 5.4.4.The bug was reproduced by calling a static UFunction from a Blueprint Function Library with a signature containing a reference-to-pointer
Outparameter, such as:void ExampleFunction(..., UObject*& OutObjectParam, ...);The following conceptual test confirms the fix. On an unpatched build, this call fails. With this patch, it succeeds.
Test Script:
Checklist