GraphicRaycaster.Raycast ArgumentOutOfRangeException
Hello, I am running into a situation in my game where I am able to reliably reproduce an ArgumentOutOfRangeException within the Graphic Raycaster in Unity 2018.3.3f1. I am using PointerInputModule and calling GetMousePointerEventData(0). The stack trace points to line 311 within GrpahicRaycaster.cs passing an incorrect index value. Here is my call stack when I break at the ArgumentOutOfRangeException:
System.ThrowHelper.ThrowArgumentOutOfRangeException (Unknown Source:0) System.Collections.Generic.List.get_Item (Unknown Source:0) UnityEngine.UI.Collections.IndexedSet.get_Item (IndexedSet.cs:112) UnityEngine.UI.GraphicRaycaster.Raycast (GraphicRaycaster.cs:311) UnityEngine.UI.GraphicRaycaster.Raycast (GraphicRaycaster.cs:219) UnityEngine.EventSystems.EventSystem.RaycastAll (EventSystem.cs:255) UnityEngine.EventSystems.PointerInputModule.GetMousePointerEventData (PointerInputModule.cs:277)
If I inspect the variables within the Raycast method at this exception, I get the following: As you can see, the index appears to be 23, and the class seems to think there are 24 total UI Graphics, but foundGraphics only has a count of 23.
When Raycaster tries to access the set, we can see the following values: The raycaster is accessing the 23rd element of a 23 count list.
I don't know off the top of my head what could be causing this. Could this be a Unity bug? The only thing I can think of would be that there is some sort of race condition where a UI Graphic is being removed from the set before the Raycaster is done iterating over it. If anyone has any ideas it would be greatly appreciated! This isn't super critical, but it is annoying to get exceptions fairly frequently that we can't really prevent.
Your answer
Follow this Question
Related Questions
Having an issue Making a second ray cast with a new angle 1 Answer
raycast : get normal value of linecast hit 1 Answer
Raycast doesn't hit instantiated object within same frame of instantiation. 0 Answers
Bounds and extents of a tilemap collider across differing y axes, Tilemap collider bounds 0 Answers
UI panel without Image component as Raycast target? It is possible? 5 Answers