You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Phaser.Math.RND.weightedPick sometimes samples the element at index array.length (past the end) and returns undefined. For an array of length 1, this happens about 30% of the time.
Since v3.70.0, the random value before flooring is Math.pow(this.frac(), 2) * array.length + 0.5. The maximum value this can have is (array.length + 0.5). Any value between array.length and array.length + 0.5 will floor to array.length, access past the end and return undefined.
Prior to v3.70.0, the distribution of random values before flooring ranged from 0.5 to (array.length - 0.5) which caused the first and last elements to be undersampled as noted in #6562. The fix committed in f844e96 increased the upper bound of random values before flooring to (array.length + 0.5), which addressed the issue of undersampling the last element but now also samples past the end. Furthermore, it intentionally continues to undersample the first element (despite what it says in the 3.70.0 release note).
The fix suggested by @samme in #6562 would have corrected undersampling on both ends but it was rejected. To produce a distribution almost identical to the one before v3.70.0 except without undersampling the last element, the function sould be:
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.
Version
Description
Phaser.Math.RND.weightedPick sometimes samples the element at index
array.length
(past the end) and returns undefined. For an array of length 1, this happens about 30% of the time.Since v3.70.0, the random value before flooring is
Math.pow(this.frac(), 2) * array.length + 0.5
. The maximum value this can have is (array.length + 0.5). Any value between array.length and array.length + 0.5 will floor to array.length, access past the end and return undefined.Example Test Code
Also, this example breaks: https://labs.phaser.io/view.html?src=src\tilemap\endless%20map.js&v=3.70.0
Additional Information
Prior to v3.70.0, the distribution of random values before flooring ranged from 0.5 to (array.length - 0.5) which caused the first and last elements to be undersampled as noted in #6562. The fix committed in f844e96 increased the upper bound of random values before flooring to (array.length + 0.5), which addressed the issue of undersampling the last element but now also samples past the end. Furthermore, it intentionally continues to undersample the first element (despite what it says in the 3.70.0 release note).
The fix suggested by @samme in #6562 would have corrected undersampling on both ends but it was rejected. To produce a distribution almost identical to the one before v3.70.0 except without undersampling the last element, the function sould be:
The modified distribution is in green:
The text was updated successfully, but these errors were encountered: