Fix unmanaged→managed event marshalling order and return conversion in source generator#525
Conversation
Agent-Logs-Url: https://github.com/ikkentim/SampSharp/sessions/6ea67a11-23a4-4a08-a311-4416835d27cc Co-authored-by: ikkentim <2820647+ikkentim@users.noreply.github.com>
| } | ||
|
|
||
| private static ExpressionSyntax AddReturnValueAssignmentToInvoke(MarshallingStubGenerationContext ctx, ExpressionSyntax invoke) | ||
| private static ExpressionSyntax AddReturnValueAssignmentToInvoke(MarshallingStubGenerationContext ctx, ExpressionSyntax invoke, MarshalDirection marshallingDirection) |
There was a problem hiding this comment.
@copilot why add marshallingDirection parameter? Why not use ctx.ReturnValue.Direction like it did before?
There was a problem hiding this comment.
I added marshallingDirection because ctx.ReturnValue.Direction no longer reliably indicates the invocation assignment target. For event delegates we set return context to UnmanagedToManaged to select marshaller mode, but the invoke result is still managed and must be assigned to __retVal first. Using ctx.ReturnValue.Direction here could assign directly to native and break the flow; using generator direction keeps assignment correct (commit cbe8157).
There was a problem hiding this comment.
@copilot are you sure about that? Look to me as if the change in src/SampSharp.SourceGenerator/Generators/OpenMpEventHandlerSourceGenerator.cs was the actual culprit of the bug
There was a problem hiding this comment.
You were right—the OpenMpEventHandlerSourceGenerator return-direction change was the key mismatch. I’ve now simplified this accordingly by removing the extra marshallingDirection parameter and using ctx.ReturnValue.Direction again, while keeping the corrected assignment target logic. Fixed in 2af5e80.
Agent-Logs-Url: https://github.com/ikkentim/SampSharp/sessions/0cdfb235-a1a5-49d1-9153-3ffcaddd2964 Co-authored-by: ikkentim <2820647+ikkentim@users.noreply.github.com>
…voke phase Agent-Logs-Url: https://github.com/ikkentim/SampSharp/sessions/0adbebfe-d1f1-48d1-88f7-506cf1d1eb4a Co-authored-by: ikkentim <2820647+ikkentim@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ikkentim/SampSharp/sessions/0adbebfe-d1f1-48d1-88f7-506cf1d1eb4a Co-authored-by: ikkentim <2820647+ikkentim@users.noreply.github.com>
…nt-npcs * origin/main: Fix unmanaged→managed event marshalling order and return conversion in source generator (#525) Refactor: Convert player classes to ECS components (#513) Implement rich command processor (#523) Configure artifact retention: 14 days for PRs, 90 days for push (#522) docs: Remove 'open.mp only' restriction from IsGhostModeEnabled (#520) fix: Windows build scripts fail correctly on build errors (#518) Fix 'cdecl' attribute ignored warnings in Linux x86_64 builds (#516)
outparameter behavior in unmanaged→managed generationout boolevent parameter scenario