Closed pancelor closed 1 year ago
(if the history looks odd it's because I accidentally referenced the original repo's issue number instead of this repo; I force pushed an amended version of the commit. hopefully that doesn't cause problems)
Aah, I thought I found all of the infinite loop edge cases, but this is one case that I overlooked. Thanks for the report! I agree that a proper "consume" fix would be better, but I don't know when I'll have time to look into this, so I'll happily take your fix in the meanwhile.
Repro steps to get PS+ into an infinite loop inside
getTilesTraversingPoints
:A picture is worth 1000 words: clicking at the green circle sends input to both the pullout menu and also the game, and results in an infinite loop:
35 is related, and the root cause is similar:
When coords.x is
NaN
and the console.warn fires,coords.x
is nan, somousePixelX
is nan (line A), so x2 is nan (line B), then on a later click(?) x1 is nan (line C). Then something aboutgetTilesTraversingPoints(NaN,NaN,42,42)
(line D) causes a infinite loop. probably becausewhile(cellX1 !== cellX2
is always true because cellX1 is nan? (I didn't look into this too closely). (note: my explanation here is not quite right, because I added some console.logs and never noticed x2 being nan inside getTilesTraversingPoints -- only x1 and y1 were nan)I think that fixing this should probably involve making the pullout menu "consume" input events and not pass them down into the game? Some sort of refactor that makes it impossible for inputs to affect both the pullout menu and the game canvas at the same time.
I have a quick fix in the interim; I'll make a PR shortly