GPU Picker crashes on canvas resize

Here is a playground with a bug example. All you need to do:

  1. Open link https://playground.babylonjs.com/#XJKQOC#4
  2. Resize canvas. You can move the splitter between the code part and the canvas
  3. Check the console and see the bug:

The problem is that the GPU picker uses the same array it got from setPickingList, but that array can be changed. So, to avoid such problems, the array must be cloned.

2 Likes

I believe this issue should be not considered as a bug. Cloning the array in the setPickingList will lead to performance drop (no matter how tiny it will be it will be still there). Writing too defensive code with lot of checks and presumptions always kills the performance.


Quite bizarre approach (no offence) to set the pickng list array in the middle of the loop and keep modifying it further in the loop. However kudos for finding the issue so at least we should mention this in the docs.

As Roland said we cannot implement defensive solutions without killing perf. It is up to the user to be cautious here. The picker assumes the array won’t change and if it does the user must do the cloning

Okay.

But then maybe you need to use similar logic as in RenderTarget Texture:

Because it is unexpected that logic will be broken by changes in the outside array. It can be beneficial to track array changes to make the picker more performance-friendly instead of supplying a new array each time.

And also it will be greater to add information regarding that in the help

Wanna do a PR?