Webgl builds crashes when clicking screen on some IOS devices if UIToolkit is in the project

I am getting a crash on some IOS devices whenever I click the screen and have UIToolkit elements in the project. So far I have experienced these crashes on some devices with IOS 15.3 and IOS 14.1. It seems to be the pointerId in the PointerEventData that is too high and causes an out of range exception in several places. I have managed to work around the issue for now by adding a check in the il2cpp generated code of the
PointerInputModule_GetTouchPointerEventData method. I am currently simply setting the pointerId to 0 if it is 32 or higher which seems to have fixed the crash. Of course this is far from ideal and might very well have other unwanted consequences that I have not discovered yet. I have logged an issue for it here https://fogbugz.unity3d.com/default.asp?1418189_uivfc0v740t5e71t which should also include a simple repro case project.

Thank you for opening a bug report! This will help us immensely to figure out what the issue is there with the interaction between UIToolkit and WebGL on iOS.

A quick thing I wanted to point out after taking a quick look at the report is that WebGL crashing on load in iOS 15.4 is caused by Apple’s update, there’s a long discussion of it here as well as a workaround: iOS 15 + WebGL 2 issue

1 Like

Thanks.
I now also tested with the mentioned workaround for IOS 15.4 and while that solves the crash on load the UIToolkit crash also happens on this IOS version.

Any news on this problem?
@SolidJakob can you explain how did you edit the il2cpp code? I see that it is just a workaround but if it works I’d like to use it

This is how we are doing it right now:

  1. Build the game for web normally.

Find the following code in one of the UnityEngine.UI.cpp files in Library\Bee\artifacts\WebGL\il2cppOutput\cpp (it might not be exactly the same)
// var created = GetPointerData(input.fingerId, out pointerData, true);
int32_t L_0;
L_0 = Touch_get_fingerId_mC1DCE93BFA0574960A3AE5329AE6C5F7E06962BD((&___input0), NULL);
bool L_1;
L_1 = PointerInputModule_GetPointerData_m8D1C52EE44136560312932072786A2B5AA2C8BE5(__this, L_0, (&V_0), (bool)1, NULL);
V_1 = L_1;
// pointerData.Reset();
PointerEventData_t9670F3C7D823CCB738A1604C72A1EB90292396FB* L_2 = V_0;

Add the following code just below it
if(L_2->___U3CpointerIdU3Ek__BackingField_12 >= 32){
L_2->___U3CpointerIdU3Ek__BackingField_12 = 0;
}
4. Build the game for web again, make sure not to do a clean build

Like this? It didn’t work :frowning: still getting “Out of bounds memory access”.
I double checked and the artifact did not get clean on the second build

Yes that is how I did it. I have tried it on Unity 2021.2.13f and 2021.2.19f so far and both those have worked so far with the fix.

iOS maps pointer IDs to random numbers, while they are incremental from 1 on other platforms. I suspect UIToolkit has a bug where it’s expecting the 1-based incremental IDs. I had to deal with this for the mobile keyboard. I’ll add notes to the bug for the person investigating it, this is probably the problem.

2 Likes

I tried building with Unity 2022.1.0b16 and it works.
I have to fix flickering and graphical glitches now…

EDIT: The graphical problems have been solved by downgrading from OpenGL 2 to OpenGL 1 in the Project Settings

I am tried to taking capture screenshot on iOS from safari and chrome browser! When I clicked capture button in game it goes to completely freeze. But I test my game on android and capture screenshot it working fine. Here is the link of my game https://bkashverse.com/ios/ , it’s works both ios and android browser, the only problem is when I capture a screen shot in ios safari, my webgl game completely freeze / Crashed…

1 Like