fix(keybinds): Prevent crash on keypress before settingClass is initialized #27
Loading…
Reference in a new issue
No description provided.
Delete branch "cwcinc/PolyModLoader:0.6.3"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Mod keybind listeners are added to window as soon as registerKeybind is called, but settingClass is only set when PolyTrack first builds its settings. A keypress in between throws TypeError: Cannot read properties of undefined (reading 'checkKeyBinding') and brings up the error screen.
This bug can be reproduced in the current version by pressing keys as the game loads. Any keyboard event can trigger this error.
This fix changes this.settingClass.checkKeyBinding(...) to this.settingClass?.checkKeyBinding(...). Until settingClass exists, the condition is falsy (undefined), so the keypress is ignored and the callback doesn't run. Once the game builds its settings, keybinds work as before.
never thought I'd see the day cwc does something for pml