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

WebGL build fails with this package installed #6

Open
AgainJBC opened this issue Feb 24, 2024 · 16 comments
Open

WebGL build fails with this package installed #6

AgainJBC opened this issue Feb 24, 2024 · 16 comments

Comments

@AgainJBC
Copy link

Hi,
I have unity 2023.2.9f1 and when I install WebGLThreading Patcher my WebGL build fails with the following error:

IL2CPP error for method 'System.Void System.Threading.<>_GenericWrapper::.ctor(System.Action1)' in assembly '[projectpath]\Library\Bee\artifacts\WebGL\ManagedStripped\mscorlib.dll
System.InvalidOperationException: Attempting to return from void method 'System.Void System.Threading.<>_GenericWrapper::.ctor(System.Action1)' when there are values on the stack. Is this invalid IL code

Any ideas how to fix that ?

@StephenHodgson
Copy link

@AgainJBC
Copy link
Author

AgainJBC commented Mar 4, 2024

Here's the fix.

https://github.com/RageAgainstThePixel/com.utilities.async/pull/13/files#diff-3c2a243f73942f45e9f92906a31b6ad885205bae85be6e88bc4c90cae5754075R165

@StephenHodgson
Well ... not sure what the fix should be ? I installed your Utilities.async package but it doesnt fix the WebGL Threading patcher build error .... so I thought it is more like a replacement than fix, uninstalled WebGL Threading patcher, but then await methods are not awaited in webGL

@StephenHodgson
Copy link

Here's the fix.
https://github.com/RageAgainstThePixel/com.utilities.async/pull/13/files#diff-3c2a243f73942f45e9f92906a31b6ad885205bae85be6e88bc4c90cae5754075R165

@StephenHodgson Well ... not sure what the fix should be ? I installed your Utilities.async package but it doesnt fix the WebGL Threading patcher build error .... so I thought it is more like a replacement than fix, uninstalled WebGL Threading patcher, but then await methods are not awaited in webGL

Really? Bc I ran into the same exact build error, and needed fixing for one of my other popular packages.

Unity engineer also gave me the fix

@AgainJBC
Copy link
Author

AgainJBC commented Mar 4, 2024

@StephenHodgson
Thank you for the fast response.
Just to be sure that I understand everything well ... installing your package should fix that WebGL Threading Patcher right ? So the install process should be:

  1. Install WebGL Threading Patcher ( will throw that IL2CPP error )
  2. Install Utilities.Async

... done, error goes away and the build is now flawless ? Does the order of those 2 steps matter ?
Nothing else needs to be done/setup and the build should now work with WebGL Threading Patcher installed ?

@StephenHodgson
Copy link

@StephenHodgson Thank you for the fast response. Just to be sure that I understand everything well ... installing your package should fix that WebGL Threading Patcher right ? So the install process should be:

  1. Install WebGL Threading Patcher ( will throw that IL2CPP error )
  2. Install Utilities.Async

... done, error goes away and the build is now flawless ? Does the order of those 2 steps matter ? Nothing else needs to be done/setup and the build should now work with WebGL Threading Patcher installed ?

You only need Utilities.Async from OpenUPM. WebGL thread patcher is already part of my package as post build step.

@AgainJBC
Copy link
Author

AgainJBC commented Mar 4, 2024

@StephenHodgson
Ok so I would call it more of a replacement than a fix.
Do I need any tweaks to my code for it to work ? As typicall "var result = await function();" seems to never end awaiting for some specific methods ( Evm.ContractSend in that case ) which are probably interacting with javascript or something under the hood. Hard to say as its compiled into dll.

But the exact same line of code finished correctly on older unity version with original WebGL Threading Patcher. I had to switch to more recent version because of other WebGL stuff support unfortunatelly.

@StephenHodgson
Copy link

? As typicall "var result = await function();" seems to never end awaiting for some specific method

Sounds like those are blocking calls.

exact same line of code finished correctly on older unity version with original WebGL Threading Patcher

Sure but keep in mind, according to the Unity engineer, the call stacks have always been misaligned and broken. Which was causing some other undefined behavior. So I guess pick your poison.

@AgainJBC
Copy link
Author

AgainJBC commented Mar 5, 2024

@StephenHodgson
Ok, thank you for your time and willingess then.

@Xantomen
Copy link

Xantomen commented Dec 5, 2024

Hi there @StephenHodgson ! I've tried this awesome repo with your fix (importing Utilities.Async (2.2.1) from OpenUPM) in Unity 6 and I'm getting the same error as OP referenced. Windows machine, WebGL build.

Can't build due to:
C:\Program Files\Unity\Hub\Editor\6000.0.23f1\Editor\Data\il2cpp\build\deploy\il2cpp.exe @Library\Bee\artifacts\rsp\7245429231228120668.rsp Error: IL2CPP error for method 'System.Void System.Threading.<>_GenericWrapper::.ctor(System.Action1)' in assembly 'C:\UnityProjects\TestProject\Library\Bee\artifacts\WebGL\ManagedStripped\mscorlib.dll'
System.InvalidOperationException: Attempting to return from void method 'System.Void System.Threading.<>_GenericWrapper::.ctor(System.Action1<T>)' when there are values on the stack. Is this invalid IL code? at Unity.IL2CPP.MethodBodyWriter.WriteReturnStatement() + 0x4ea at Unity.IL2CPP.MethodBodyWriter.ProcessInstruction(Node, InstructionBlock, ResolvedInstruction) + 0x85e at Unity.IL2CPP.MethodBodyWriter.GenerateCodeRecursive(Node, ReadOnlyDictionary2) + 0x827
at Unity.IL2CPP.MethodBodyWriter.Generate() + 0x72f
at Unity.IL2CPP.CodeWriters.CodeWriterExtensions.WriteMethodWithMetadataInitialization(IGeneratedMethodCodeWriter, String, Action2, String, MethodReference, WritingMethodFor) + 0x2ef at Unity.IL2CPP.MethodWriter.WriteMethodDefinition(AssemblyWriteContext, IGeneratedMethodCodeWriter, MethodReference) + 0x40a at Unity.IL2CPP.SourceWriter.WriteTypesMethods(SourceWritingContext, IGeneratedMethodCodeWriter, TypeWritingInformation&, NPath, Boolean) + 0x560 at Unity.IL2CPP.SourceWriters.SourceWriterBase2.WriteItem(StreamWorkItemData2) + 0x1fc at Unity.IL2CPP.Contexts.Scheduling.Streams.FileLevelParallelStreamManager3.WorkerWriteItemsToFile(WorkItemData2 data) + 0x1ed at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler1.WorkerLoop(Object data) + 0x60e

UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()
`

Have you been able to confirm the fix works in your machine for Unity 6?

Thank you!

@StephenHodgson
Copy link

StephenHodgson commented Dec 5, 2024

Have you been able to confirm the fix works in your machine for Unity 6?

I have not seen any issues so far. I have build automation and unit tests that run every week to confirm

[edit]
But I see now they don't build for webgl. So I'll add that as smoke test.

@StephenHodgson
Copy link

@Xantomen seems fine for unity 6

results

some issue with 2020.x tho

@Xantomen
Copy link

Xantomen commented Dec 5, 2024

Weird, 20 minutes ago when I was checking the smoke tests Unity 6 was also showing as failing on the WebGL-Test step, now it's showing fine.

Oh well, thank you very much for checking, and so quick! Very clever to have those automatic tests :)

I can't imagine what step I would be doing wrong however, I'm only adding the ThreadingPatcher folder in my Assets folder and then adding the Utilities.Async package, building an empty scene. uhm

Any ideas at all of something obvious I might be doing wrong?

I will check tomorrow on other versions of Unity on my machine just for sanity. If I'm setting it up wrong it should fail me in those too I would guess.

Thank you!

@AgainJBC
Copy link
Author

AgainJBC commented Dec 5, 2024

@Xantomen
I ended up switching my code to Awaitables, they works flawlessly in webGL.

@StephenHodgson
Copy link

StephenHodgson commented Dec 5, 2024

yeah with Unity 6 the Awaitables have much better support.

@Xantomen
Copy link

Xantomen commented Dec 6, 2024

Wow I'm a big dummy, it had completely skipped my understanding when reading your texts above that you were not meant to use both WebGLThreadingPatcher and Utilities.Async together, just the second one. I feel silly now hahaha.

Thanks guys! The second package alone works very well for what I needed. I'll spread the word.

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

No branches or pull requests

3 participants