KMKfw / kmk_firmware

Clackety Keyboards Powered by Python
https://kmkfw.zulipchat.com
Other
1.39k stars 475 forks source link

[BUG] Specifying "KC.MO(1)" in code.py crashes CircuitPython #893

Closed Bob837217 closed 1 year ago

Bob837217 commented 1 year ago

Describe the bug If I put an an alias like "FN = KC.MO(1)" after a "Layers()" instantiation, CircuitPython crashes, enters Safe Mode and reports that a crash occurred.

To Reproduce Steps to reproduce the behavior:

Here are two minimal examples: This code works with no crash:

    import time
    from kmk.kmk_keyboard import KMKKeyboard
    from kmk.modules.layers import Layers
    from kmk.keys import KC
    keyboard = KMKKeyboard()
    FN = KC.MO(1)
    layers = Layers()
    while True:
        print("Waiting")
        time.sleep(2)

And this code causes a crash:

    import time
    from kmk.kmk_keyboard import KMKKeyboard
    from kmk.modules.layers import Layers
    from kmk.keys import KC
    keyboard = KMKKeyboard()
    layers = Layers()
    FN = KC.MO(1)
    while True:
        print("Waiting")
        time.sleep(2)

The difference is that "FN = KC.MO(1)" occurs after "layers = Layers()" - this causes crash. Also if (in my full keymap), I reference "KC.MO(1)" directly instead of the non working "FN" alias, this will crash the same way.

Expected behavior I expect to be able to define the FN alias and use it in my keymap without a CircuitPython crash.

Debug output

Running in safe mode! Not running saved code.

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Hard fault: memory access or instruction error.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.

Additional context

Additionally, if I use the FN alias (from the working non-crashing code) in a keymap for my Fn key, no switch to layer 1 occurs and my layer 1 codes do not get emitted.

Here is the debug REPL

753568 kmk.keyboard: <Event: key_number 70 pressed>: Key(code=1001, has_modifiers=None)
753572 kmk.keyboard: coordkeys_pressed={70: Key(code=1001, has_modifiers=None)}
753823 kmk.keyboard: <Event: key_number 70 released>: Key(code=1001, has_modifiers=None)
753826 kmk.keyboard: coordkeys_pressed={}
Bob837217 commented 1 year ago

Ok, reported same on Adafruit CircuitPython github and the issue is that I was building my CircuitPython directly from "main" branch, which is all alpha level code and not intended for end users. I switched to latest non main branch "8.2.x", built from there and this problem does not occur.

main branch version which produced this error: "Adafruit CircuitPython 9.0.0-alpha.1-37-g4563c35908 on 2023-09-12; EK68Custom with rp2040" 8.2.x branch version which resolved this error: "Adafruit CircuitPython 8.2.6-5-g37180b28dd on 2023-09-23; EK68Custom with rp2040"

Closing this issue off.