Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception invoking lua callback with Wait #2457

Open
DaniGP17 opened this issue Apr 13, 2024 · 0 comments
Open

Exception invoking lua callback with Wait #2457

DaniGP17 opened this issue Apr 13, 2024 · 0 comments
Labels
bug ScRT: C# Issues/PRs related to either C# scripting runtimes triage Needs a preliminary assessment to determine the urgency and required action

Comments

@DaniGP17
Copy link

What happened?

Currently in C# v1 I have created an export that takes a callback as an argument, and directly invokes it.

public class ServerMain : BaseScript
    {
        public ServerMain()
        {
            Exports.Add("TestExport", testExport);
        }
        
        void TestExport(object obj)
        {
	        CallbackDelegate callback = (CallbackDelegate)obj;
	        callback.Invoke();
        }
    }

In lua I am executing the callback in a thread (not important) and I am passing as an argument to the export a function so that C# executes it, if I execute it without having the Wait inside the function there is no problem, but if there is a Wait inside From the function I get an error.

Citizen.CreateThread(function()
    Wait(1000)
    exports["testing-cs"]:TestExport(function()
        Wait(1000)
        print("FINISH")
    end)
end)

Error:

[    script:testing-cs] SCRIPT ERROR in reference call: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
[    script:testing-cs] Parameter name: index
[    script:testing-cs]
[  script:test-lua] SCRIPT ERROR: error object is not a string

I added a try catch to the exact line that is giving the error so I can provide more detail info:

[    script:testing-cs] Error invoking callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
[    script:testing-cs] Parameter name: index
[    script:testing-cs]   at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in <fbc4ec45371543bfba3678ebb82caf6d>:0
[    script:testing-cs]   at (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object,int)
[    script:testing-cs]   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet] (System.Runtime.CompilerServices.CallSite site, T0 arg0, T1 arg1) [0x0011d] in <cf8f429092f345a6bd742c3476e00e06>:0
[    script:testing-cs]   at CitizenFX.Core.MsgPackDeserializer+<>c__DisplayClass36_1.<CreateRemoteFunctionReference>b__1 (System.Object res, System.Object err) [0x0025f] in C:\fivem\code\client\clrcore\MsgPackDeserializer.cs:285
[    script:testing-cs]   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
[    script:testing-cs]   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <fbc4ec45371543bfba3678ebb82caf6d>:0
[    script:testing-cs]    Exception_EndOfInnerExceptionStack
[    script:testing-cs]   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <fbc4ec45371543bfba3678ebb82caf6d>:0
[    script:testing-cs]   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <fbc4ec45371543bfba3678ebb82caf6d>:0
[    script:testing-cs]   at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <fbc4ec45371543bfba3678ebb82caf6d>:0
[    script:testing-cs]   at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <fbc4ec45371543bfba3678ebb82caf6d>:0
[    script:testing-cs]   at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <fbc4ec45371543bfba3678ebb82caf6d>:0
[    script:testing-cs]   at CitizenFX.Core.FunctionReference.Invoke (System.Int32 reference, System.Byte[] arguments) [0x000ad] in C:\fivem\code\client\clrcore\FunctionReference.cs:72

This is the exact line that is giving the error.

The behavior is a little strange, everything works perfectly, the only thing that happens is that the error is displayed.

Expected result

Error not shown

Reproduction steps

  1. Create a C# script
  2. Add a export that take a CallbackDelegate and invoke it
  3. Create a Lua script
  4. Use that export sending a function as arguments to the export
  5. Inside the function that is being sended to the export add a Wait

Importancy

Slight inconvenience

Area(s)

FiveM, ScRT: C#

Specific version(s)

FiveM 7900 & build from source

Additional information

The error occurs on server and client

@DaniGP17 DaniGP17 added bug triage Needs a preliminary assessment to determine the urgency and required action labels Apr 13, 2024
@github-actions github-actions bot added the ScRT: C# Issues/PRs related to either C# scripting runtimes label Apr 13, 2024
@DaniGP17 DaniGP17 changed the title Exception invoking lua callback with Wait by C# Exception invoking lua callback with Wait Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ScRT: C# Issues/PRs related to either C# scripting runtimes triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

No branches or pull requests

1 participant