xblax / flashforge_ad5m_klipper_mod

Unoffical mod for Flashforge Adventurer 5M (Pro) 3D printers to run Moonraker, custom Klipper, Mainsail & Fluidd
GNU General Public License v3.0
82 stars 4 forks source link

klipperscreen: camera panel does not load, crashes after error message #65

Closed xblax closed 2 months ago

xblax commented 2 months ago

Tested the 'Camera' function of KlipperScreen. It fails to load on shows an error, on screen and in the log. After pressing the button 'Back' it Klipper Screen seems to hang. The screen just stays black.

Might be fixed by enabling libmpv in buildroot.

2024-03-13 21:37:48,447 [screen.py:show_error_modal()] - Showing error modal: Unable to load panel camera Cannot find libmpv in the usual places. Depending on your distro, you may try installing an mpv-devel or mpv-libs package. If you have libmpv around but this script can't find it, consult the documentation for ctypes.util.find_library which this script uses to look up the library filename.

Traceback (most recent call last):
  File "/root/printer_software/KlipperScreen/screen.py", line 319, in show_panel
    self.panels[panel_name] = self._load_panel(panel).Panel(self, title, **kwargs)
                              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/printer_software/KlipperScreen/screen.py", line 306, in _load_panel
    return import_module(f"panels.{panel}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/root/printer_software/KlipperScreen/panels/camera.py", line 1, in <module>
    import mpv
  File "/root/printer_software/KlipperScreen/KlipperScreen-env/lib/python3.11/site-packages/mpv.py", line 52, in <module>
    raise OSError("Cannot find libmpv in the usual places. Depending on your distro, you may try installing an mpv-devel or mpv-libs package. If you have libmpv around but this script can't find it, consult the documentation for ctypes.util.find_library which this script uses to look up the library filename.")
OSError: Cannot find libmpv in the usual places. Depending on your distro, you may try installing an mpv-devel or mpv-libs package. If you have libmpv around but this script can't find it, consult the documentation for ctypes.util.find_library which this script uses to look up the library filename.

2024-03-13 21:37:48,782 [functions.py:get_software_version()] - Error getting git version: b'fatal: not a git repository (or any of the parent directories): .git\n'
2024-03-13 21:37:50,259 [KlippyGtk.py:Dialog()] - Showing dialog Error (width=800, height=480)
consp commented 2 months ago

Good one, don't have a camera so never tested it properly. Including libmpv would probably fix it, shoud't be too much of an issue.

xblax commented 2 months ago

Btw. most webcams supported by Linux should work, if you have any. Also don't have the original camera yet.

consp commented 2 months ago

Good point, should have one somewhere, ancient logitech thing so should work. Pro should arrive in a few days, maybe I'll just wait for that.

I'll also run a ldd on all the compiled modules in klipperscreen to check what it uses as well, just to be sure.

the-redone commented 2 months ago

Was going to report this last night, but thought someone might have already :)

Tried with a camera plugged in and removed, same error both times

Selecting the info icon on the main menu (bottom left corner) also crashes klipper, "Klipper has shutdown, Shutdown due to webhooks request" only a firmware restart gets it working again, klipper restart ends in another error.

consp commented 2 months ago

Tried with a camera plugged in and removed, same error both times

That's the be expected though. The library which is missing gets loaded quite early. I'll check if it's the simple missing lib error by adding it tonight (need to rebuild anyway due to the mismatch in setsid) and see if that fixes it.

firmware restart gets it working again, klipper restart ends in another error.

if you know how to ssh to the machine (see docks for login credentials) execute:

/etc/init.d/S80klipperscreen stop
/etc/init.d/S80klipperscreen start

And it should restart.

There is no simple "patch" so for now try avoid the camera panel.

Selecting the info icon on the main menu (bottom left corner) also crashes klipper, "Klipper has shutdown, Shutdown due to webhooks request" only a firmware restart gets it working again, klipper restart ends in another error.

That's to be expected as it's the emergency abort. Same as pressing the emergency abort in mainsail/fluidd.

consp commented 2 months ago

Just edited the message; That's the emergency abort, it kills everything. Same as in mainsail/fluidd. Pretty much what it's supposed to do afaik :) It it's not let me know, I usually do the emergency shutdown by unplugging mains.

the-redone commented 2 months ago

Just edited the message; That's the emergency abort, it kills everything. Same as in mainsail/fluidd. Pretty much what it's supposed to do afaik :)

Ye just seen the edit, I'd never noticed it before on other klipper machines I've had.

Thanks for getting back to me anyway

consp commented 2 months ago

I'd never noticed it before on other klipper machines I've had

If I'm not mistaken you can disable it so the others might have done that or just not added it to their interface. But since it's alpha/beta software better let it be in there just to be sure.

consp commented 2 months ago

Note: this pulls in ffmpeg. The tarball will get a LOT bigger. Ok not that a lot, just 15mb.

Unable to load panel camera libass.so.9

Now it's just messing with me

consp commented 2 months ago

It works ... but ... at about 0.000000001 FPS. still waiting for the first frame to render.

...

I can report the OOM daemon works as expected.

Mar 14 19:36:21 ADM5 kern.info kernel: [  576.880423] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),task=python3,pid=1657,uid=0
consp commented 2 months ago

I guess the best option is to disable the camerascreen. Unless klipperscreen can manage some DMA magic and render directly to screen this is not going to happen. It pretty much collects the raw input, processes it though ffmpeg (libs) and then renders it on screen with a software scaler. This is all VERY memory intensive and also very very very .... very slow.

xblax commented 2 months ago

Yes, just disable it then. I guess showing the camera on the printer screen is a bit pointless anyway.

consp commented 2 months ago

The good thing coming from this excersise is the proper test of the OOM killer I guess. Since Klipperscreen is the lowest (highest niceness) it gets killed as it should.

I'll create a patch which disables the panel in config. Should be possible. If not I'll hard-disable it in code.

consp commented 2 months ago

"Fixed" in https://github.com/consp/KlipperScreen/commit/f6af6e5bbdc97a97c7a050982b9e240b59a4623b since it will crash klipper (and maybe the system) due tot memory overusage forcing the OOM to kick in.