Skip to content

test enabling AOT compilation when exporting samples#94

Draft
dogboydog wants to merge 8 commits into
developfrom
AOT
Draft

test enabling AOT compilation when exporting samples#94
dogboydog wants to merge 8 commits into
developfrom
AOT

Conversation

@dogboydog
Copy link
Copy Markdown
Collaborator

@dogboydog dogboydog commented Jun 4, 2025

@dogboydog dogboydog changed the title test enabling AOT compilation test enabling AOT compilation when exporting samples Jun 4, 2025
@dogboydog
Copy link
Copy Markdown
Collaborator Author

Currently fails to export on windows

YarnSpinner-Godot failed with 2 error(s) (5.7s) → .godot\mono\temp\bin\ExportRelease\win-x64\YarnSpinner-Godot.dll
EXEC : error : The given key '[YarnSpinner-Godot]YarnSpinnerGodot.YarnTask+d__7`1' was not present in the dictionary.
C:\Users\chris.nuget\packages\microsoft.dotnet.ilcompiler\8.0.16\build\Microsoft.NETCore.Native.targets(308,5): error MSB3073: The command ""C:\Users\chris.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.16\tools\ilc" @"C:\Users\chris\RiderProjects\YarnSpinner-Godot.godot\mono\temp\obj\ExportRelease\win-x64\native\YarnSpinner-Godot.ilc.rsp"" exited with code 1.

@dogboydog dogboydog marked this pull request as draft June 29, 2025 16:56

return await Task.WhenAll(uniTasks);
}
// public static async partial YarnTask<T[]> WhenAll<T>(params YarnTask<T>[] tasks)
Copy link
Copy Markdown
Collaborator Author

@dogboydog dogboydog Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncommenting these lines causes a compilation failure under AOT, maybe due to using the generic types?

var paramIndex = i;
// var paramsArray = new List<object?>();
var paramsArray = Array.CreateInstance(parameterArrayElementType!, argumentCount - i);
var paramsArray = new List<object?>();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about these changes. Made them based on AOT warnings

@dogboydog
Copy link
Copy Markdown
Collaborator Author

I actually got my more complex game project mostly working when I retested, after adding some settings to the .props and csproj file related to assembly trimming. However, I still got some errors I don't understand that seems to be AOT related :
ERROR: System.InvalidCastException: Specified cast is not valid.
at YarnSpinnerGodot.LineProviderBehaviour.SetGodotClassPropertyValue(??? name, ??? value) + 0xe2
at Dispossessed.CoreTextLineProvider.SetGodotClassPropertyValue(??? name, ??? value) + 0xb7
at Dispossessed!+0x913b53

Additionally it seems like my changes to get the project compiling under AOT to command dispatching breaks commands with integer type arguments. This may be because I tried to make the arguments array a list of objects since before it was using reflection based APIs that are incompatible with AOT from what I read, and an integer is a primitive & not an object to my understanding. I don't know how to change the code right now so that it works under AOT and also supports all the required data types for command arguments

@dogboydog
Copy link
Copy Markdown
Collaborator Author

YS-Godot SQLite Variable Storage sample error:

E 0:01:51:754   void YarnSpinnerGodot.YarnTask+<Forget>d__15.MoveNext(): System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'Internal error: Unknown command dispatch result status YarnSpinnerGodot.CommandDispatchResult')
  at YarnSpinnerGodot.DialogueRunner.OnCommandReceivedAsync(Command command) in /home/chris/Documents/code/YarnSpinner-Godot/addons/YarnSpinner-Godot/Runtime/DialogueRunner.cs:line 701
  at YarnSpinnerGodot.YarnTask.Forget() in /home/chris/Documents/code/YarnSpinner-Godot/addons/YarnSpinner-Godot/Runtime/Async/YarnTask/YarnTask.Task.cs:line 32
 <C# Source>   YarnTask.Task.cs:32 @ void YarnSpinnerGodot.YarnTask+<Forget>d__15.MoveNext()
 <Stack Trace> GD.cs:382 @ void Godot.GD.PushError(System.Object[])
               YarnTask.Task.cs:32 @ void YarnSpinnerGodot.YarnTask+<Forget>d__15.MoveNext()
               :0 @ void System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<TStateMachine>(TStateMachine&)
               :0 @ void YarnSpinnerGodot.YarnTask.Forget()
               DialogueRunner.cs:635 @ void YarnSpinnerGodot.DialogueRunner.OnCommandReceived(Yarn.Command)
               :0 @ void Yarn.VirtualMachine.RunInstruction(Yarn.Instruction)
               :0 @ void Yarn.VirtualMachine.Continue()
               :0 @ void Yarn.Dialogue.Continue()
               DialogueRunner.cs:743 @ void YarnSpinnerGodot.DialogueRunner+<OnLineReceivedAsync>d__62.MoveNext()
               :0 @ void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
               :0 @ void System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, object, System.Threading.Tasks.Task&)
               :0 @ void System.Threading.Tasks.Task.RunContinuations(object)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
               YarnTask.AsyncMethodBuilder.cs:52 @ void YarnSpinnerGodot.YarnTaskMethodBuilder.SetResult()
               DialogueRunner.cs:863 @ void YarnSpinnerGodot.DialogueRunner+<RunLocalisedLine>d__63.MoveNext()
               :0 @ void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
               :0 @ void System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, object, System.Threading.Tasks.Task&)
               :0 @ void System.Threading.Tasks.Task.RunContinuations(object)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
               YarnTask.AsyncMethodBuilder.cs:52 @ void YarnSpinnerGodot.YarnTaskMethodBuilder.SetResult()
               YarnTask.Task.cs:92 @ void YarnSpinnerGodot.YarnTask+<WhenAll>d__6.MoveNext()
               :0 @ void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
               :0 @ void System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, object, System.Threading.Tasks.Task&)
               :0 @ void System.Threading.Tasks.Task.RunContinuations(object)
               :0 @ bool System.Threading.Tasks.Task.TrySetResult()
               :0 @ void System.Threading.Tasks.Task+WhenAllPromise.Invoke(System.Threading.Tasks.Task)
               :0 @ void System.Threading.Tasks.Task.RunContinuations(object)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
               YarnTask.AsyncMethodBuilder.cs:52 @ void YarnSpinnerGodot.YarnTaskMethodBuilder.SetResult()
               DialogueRunner.cs:819 @ void YarnSpinnerGodot.DialogueRunner+<>c__DisplayClass63_2+<<RunLocalisedLine>g__RunLineAndInvokeCompletion|1>d.MoveNext()
               :0 @ void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
               :0 @ void System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, object, System.Threading.Tasks.Task&)
               :0 @ void System.Threading.Tasks.Task.RunContinuations(object)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
               YarnTask.AsyncMethodBuilder.cs:52 @ void YarnSpinnerGodot.YarnTaskMethodBuilder.SetResult()
               LinePresenter.cs:380 @ void YarnSpinnerGodot.LinePresenter+<RunLineAsync>d__22.MoveNext()
               :0 @ void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
               :0 @ void System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, object, System.Threading.Tasks.Task&)
               :0 @ void System.Threading.Tasks.Task.RunContinuations(object)
               :0 @ bool System.Threading.Tasks.Task`1.TrySetResult(TResult)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetExistingTaskResult(System.Threading.Tasks.Task`1[TResult], TResult)
               YarnTask.AsyncMethodBuilder.cs:114 @ void YarnSpinnerGodot.YarnTaskMethodBuilder`1.SetResult(T)
               YarnTask.Task.cs:122 @ void YarnSpinnerGodot.YarnTask+<SuppressCancellationThrow>d__7.MoveNext()
               :0 @ void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1.MoveNext(System.Threading.Thread)
               :0 @ void System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, object, System.Threading.Tasks.Task&)
               :0 @ void System.Threading.Tasks.Task.RunContinuations(object)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
               YarnTask.AsyncMethodBuilder.cs:52 @ void YarnSpinnerGodot.YarnTaskMethodBuilder.SetResult()
               YarnTask.Task.cs:46 @ void YarnSpinnerGodot.YarnTask+<WaitUntilCanceled>d__0.MoveNext()
               :0 @ void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
               :0 @ void System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, object, System.Threading.Tasks.Task&)
               :0 @ void System.Threading.Tasks.Task.RunContinuations(object)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult()
               DefaultActions.cs:24 @ void YarnSpinnerGodot.DefaultActions+<Wait>d__0.MoveNext()
               :0 @ void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
               :0 @ void System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1.MoveNext()
               SignalAwaiter.cs:65 @ void Godot.SignalAwaiter.SignalCallback(nint, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_bool*)

{
paramsArray.SetValue(converter.Invoke(arg, i), i - paramIndex);
// todo test
paramsArray[i - paramIndex] = converter.Invoke(arg, i);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the reason you see ArgumentOutOfRangeException, it is empty the first time it runs

Suggested change
paramsArray[i - paramIndex] = converter.Invoke(arg, i);
paramsArray.Add(converter.Invoke(arg, i))

i += 1;
}

finalArgs[paramIndex] = paramsArray;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since paramsArray is a list I think this needs to be

Suggested change
finalArgs[paramIndex] = paramsArray.ToArray();

may be also makes sense to rename paramsArray into paramsList or something like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants