arcomage / arcomage-hd

Web-based, free and open source, remastered 3D clone of 3DO/NWC's 2000 card game Arcomage. 13 languages. Desktop or mobile Android iOS. Online or offline PWA. Against AI or Multiplayer (w/o server). πŸ§πŸ‘ΎπŸƒ (ts+react+redux+rxjs, CSS-based anim, WebRTC)
https://arcomage.github.io
MIT License
126 stars 28 forks source link

In rare bug mode, press any (keyboard) key to mess up cards (`useKeyDown` not unmounted) #57

Closed tomchen closed 2 years ago

tomchen commented 2 years ago

Very rare "bug mode" which is very hard to reproduce. Maybe violently press F? or AudioVolume? key to enter the "mode".

In this "bug mode", user can press any key, letter, number, F?, etc. to re-deal cards which appear in a very messy order and usually outside the screen. And dev console shows warnings: ?? executed during the lock ??. the game will try to fix that.

When the bug occurs, starting a new game of course won't get rid of the bug, user must reload the page to have a normal game back.

In the "bug mode", if user start a new game and only uses mouse and not keyboard, then everything appears to be good.

Although I don't know exactly when the bug could appear, it's likely due to useKeyDown that is not properly unmounted in EndScreen which results in unexecuted removeEventListener and keydown listener is always there. I don't know why it's not properly unmounted.

https://github.com/arcomage/arcomage-hd/blob/0df38726efe99ba7313b4c3b28ed7c872f76fefb/src/utils/useKeyDown.ts#L19-L21

tomchen commented 2 years ago

I understand now. If "Preferences" window is somehow still there when EndScreen appears, and user clicks "Apply & New Game" button before endScreenExitableDelay, then the keydown listener won't be removed and will always be there.