dynobo / normcap

OCR powered screen-capture tool to capture information instead of images
https://dynobo.github.io/normcap/
Other
1.8k stars 91 forks source link

Using AppImage on Kubuntu, sometimes the captured text cannot be pasted and NormCap exits. #638

Open SnowballV opened 1 month ago

SnowballV commented 1 month ago

What happened?

Using NormCap-0.5.5-x86_64.AppImage on Kubuntu 22.04.4, after capturing some text, sometimes the captured text cannot be pasted and next NormCap exits.

Sometimes the issue surfaces right away, with the first capture when executing the application, sometimes the issue hits after a few captures and pastes.

I've seen the issue not only with the current version 0.5.5, but since earlier versions as well, perhaps since about version 0.50, 0.51, 0.52, or 0.53.

Regarding the debug log output, as it took a few captures before the issue appeared, a very long debug log output was produced. I will post the final part of the debug log output, I hope that is sufficient. The final line includes: "Segmentation fault (core dumped)"

If I excluded a part that was essential, let me know, and I'll post a new debug log output.

How did you install NormCap?

AppImage (Linux)

Operating System + Version?

Kubuntu 22.04.4

[Linux only] Display Server (DS) + Desktop environment (DE)?

DS: Xorg, DE: KDE Plasma

Debug log output?*

[...]
01:35:46 - DEBUG   - normcap.gui.utils:22 - Save debug image as /tmp/normcap/2024-05-07_23-35-46_enhanced.png
01:35:47 - INFO    - normcap.gui.tray:285 - Text from OCR:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
01:35:47 - DEBUG   - normcap.gui.tray:328 - Copy text to clipboard
01:35:47 - DEBUG   - normcap.clipboard.handlers.windll:187 - normcap.clipboard.handlers.windll is incompatible on non-Windows systems
01:35:47 - DEBUG   - normcap.clipboard.handlers.pbcopy:23 - normcap.clipboard.handlers.pbcopy is incompatible on non-macOS systems
01:35:47 - DEBUG   - normcap.clipboard.handlers.qtclipboard:38 - normcap.clipboard.handlers.qtclipboard is compatible
01:35:47 - DEBUG   - normcap.clipboard.handlers.wlclipboard:34 - normcap.clipboard.handlers.wlclipboard is not compatible on non-Linux systems and on Linux w/o Wayland
01:35:47 - DEBUG   - normcap.clipboard.handlers.xsel:36 - normcap.clipboard.handlers.xsel is compatible
01:35:47 - DEBUG   - normcap.clipboard.handlers.xclip:42 - normcap.clipboard.handlers.xclip is compatible
01:35:47 - DEBUG   - normcap.clipboard.main:73 - Compatible clipboard handlers: ['QT', 'XSEL', 'XCLIP']
01:35:47 - DEBUG   - normcap.clipboard.handlers.qtclipboard:43 - normcap.clipboard.handlers.qtclipboard requires no dependencies
01:35:47 - DEBUG   - normcap.clipboard.handlers.xsel:45 - normcap.clipboard.handlers.xsel dependencies are installed (/tmp/.mount_NormCagkXLhx/usr/bin/xsel)
01:35:47 - DEBUG   - normcap.clipboard.handlers.xclip:51 - normcap.clipboard.handlers.xclip dependencies are installed (/tmp/.mount_NormCagkXLhx/usr/bin/xclip)
01:35:47 - DEBUG   - normcap.clipboard.main:80 - Available clipboard handlers: ['QT', 'XSEL', 'XCLIP']
01:35:47 - DEBUG   - normcap.clipboard.handlers.qtclipboard:38 - normcap.clipboard.handlers.qtclipboard is compatible
01:35:47 - INFO    - normcap.clipboard.main:35 - Text copied to clipboard using QT
01:35:47 - DEBUG   - normcap.gui.notification:173 - Send notification via QT
/tmp/.mount_NormCagkXLhx/AppRun: line 11: 23799 Segmentation fault      (core dumped) "${APPDIR}/usr/python/bin/python3" -u -s -X utf8 -c "import runpy, sys; sys.path.pop(0); runpy.run_module('${BRIEFCASE_MAIN_MODULE}', run_name='__main__', alter_sys=True)" "$@"
SnowballV commented 1 month ago

Later, I realized, to generate the debug log I captured text in Latin, while NormCap was set to English. That was not smart. However, the issue presents the same way if I capture text in English, so I guess the log is still valid.

dynobo commented 1 month ago

Hi @SnowballV , thanks for reporting this issue with all information. :+1:

The Segmentation fault indicates, that something fundamentally breaks on your system. I'll probably have to reproduce the issue, to get the root cause, but this might take a while.

If you could do some further tests in the meanwhile, that would be super helpful:

  1. According to your log, the crash appears after "copy to clipboard". (The text might still not yet be registered in the clipboard, though.) My hypothesis is, that one of the later steps (either "show notification" or "quit/hide application") causes the crash.
    1. Could you please try to turn the "Show notification" setting off and test if it makes a difference?
    2. With the same idea, could you toggle the "Show in Tray" setting?
  2. To verify, if the clipboard handler is the culprit, you could try a different one by running: ./NormCap-0.5.5-x86_64.AppImage --clipboard-handler=xclip (requires sudo apt install xclip, if not done already)
SnowballV commented 1 month ago

Thanks very much for the test suggestions.

Again, I used NormCap-0.5.5-x86_64.AppImage on Kubuntu 22.04.4.

First, I disabled "Show notification". With "Show notification" disabled, I could produce no crash.

I then re-enabled "Show notification". With "Show notification" re-enabled, most attempts produced a crash. At least one out of two, but sometimes five out of five. As the notification was shown, the application crashed. And I wasn't able to paste the captured text from the clipboard. I guess that shows the captured text was not yet registered in the clipboard, even though the notification said so.

Next, with "Show notification" re-enabled, I disabled "Keep in system tray". N.B. Was that what you meant when you wrote 'toggle the "Show in Tray" setting?' With "Show notification" re-enabled, and "Keep in system tray" disabled, most if not all attempts produced a crash. So, disabling "Keep in system tray" made no difference.

I re-enabled both "Show notification" and "Keep in system tray". I installed xclip. Next, I ran ./NormCap-0.5.5-x86_64.AppImage --clipboard-handler=xclip This time, I could produce no crash.

SnowballV commented 1 month ago

I tried the latest version, NormCap-0.5.6-x86_64.AppImage. It has the same issue. As I saw the changelog, I didn't expect otherwise.

I tested the previous AppImage versions: 0.5.4, 0.5.3, and 0.5.2. AppImage versions 0.5.4 and 0.5.3 have the same issue as 0.5.5 and 0.5.6.

However, with NormCap-0.5.2-x86_64.AppImage, I cannot provoke a crash. It doesn't need "Show notification" disabled.

So it seems AppImage 0.5.2 was the last one without the issue, and 0.5.3 up to 0.5.6 have the same issue.

dynobo commented 1 month ago

Thanks for the further testing, @SnowballV . It's quite interesting that it broke between 0.5.2 and 0.5.3, because my first suspects would have been updated dependencies (PySide6 or briefcase), but those haven't changed. So it more likely is related to some refactoring I did there. Still, I probably have to replicate the crash myself to fix it, but your investigation are giving me a good head-start on where to look! :)

SnowballV commented 1 month ago

Indeed, it is interesting. In the changelog for 0.5.3, I see things were changed for clipboard handling. Seen my NormCap-0.5.5-x86_64.AppImage test results, a relation with clipboard handling does not seem unlikely. If you need me to do more testing, please let me know. For now, I can use AppImage 0.5.2.

SnowballV commented 1 month ago

I created a new debug log, now for NormCap-0.5.7-x86_64.AppImage, and now a complete log, not only the final part. OS: Kubuntu 22.04.4, DS: Xorg, DE: KDE Plasma

./NormCap-0.5.7-x86_64.AppImage -v debug
14:44:39 - INFO    - normcap:50 - Start NormCap v0.5.7
14:44:39 - DEBUG   - normcap:107 - Append /tmp/.mount_NormCaRbCOZl/usr/bin to AppImage internal PATH
14:44:39 - DEBUG   - normcap.gui.tray:70 - System info:
{'normcap_version': '0.5.7', 'python_version': '3.10.13', 'cli_args': '/tmp/.mount_NormCaRbCOZl/usr/app/normcap/__main__.py -v debug', 'is_briefcase_package': True, 'is_flatpak_package': False, 'is_appimage_package': True, 'platform': 'linux', 'desktop_environment': <DesktopEnvironment.KDE: 3>, 'display_manager_is_wayland': False, 'pyside6_version': '6.7.0', 'qt_version': '6.7.0', 'qt_library_path': '/tmp/.mount_NormCaRbCOZl/usr/app_packages/PySide6/Qt/plugins, /tmp/.mount_NormCaRbCOZl/usr/python/bin', 'locale': 'DEFAULT', 'config_directory': PosixPath('/home/xxxxx/.config/normcap'), 'resources_path': PosixPath('/tmp/.mount_NormCaRbCOZl/usr/app/normcap/resources'), 'tesseract_path': PosixPath('/tmp/.mount_NormCaRbCOZl/usr/bin/tesseract'), 'tessdata_path': PosixPath('/home/xxxxx/.config/normcap/tessdata'), 'envs': {'TESSDATA_PREFIX': None, 'LD_LIBRARY_PATH': None}, 'screens': [Screen(left=0, top=0, right=1919, bottom=1079, device_pixel_ratio=1.0, index=0, screenshot=None)]}
14:44:39 - DEBUG   - normcap.gui.settings:162 - Skip update of non existing setting (show_introduction: None)
14:44:39 - DEBUG   - normcap.gui.settings:162 - Skip update of non existing setting (cli_mode: False)
14:44:39 - DEBUG   - normcap.gui.settings:162 - Skip update of non existing setting (background_mode: False)
14:44:39 - DEBUG   - normcap.gui.settings:162 - Skip update of non existing setting (clipboard_handler: None)
14:44:39 - DEBUG   - normcap.gui.tray:384 - Listen on local socket v0.5.7-normcap.
14:44:39 - DEBUG   - normcap.screengrab.main:21 - Compatible capture handlers: ['QT', 'DBUS_PORTAL', 'DBUS_SHELL']
14:44:39 - DEBUG   - normcap.screengrab.main:28 - Available capture handlers: ['QT', 'DBUS_PORTAL', 'DBUS_SHELL']
14:44:39 - INFO    - normcap.screengrab.main:67 - Screen captured using QT
14:44:39 - DEBUG   - normcap.gui.utils:22 - Save debug image as /tmp/normcap/2024-05-19_12-44-39_raw_screen0.png
14:44:39 - DEBUG   - normcap.gui.window:51 - Create window for screen 0
14:44:40 - DEBUG   - normcap.gui.window:141 - Set window of screen 0 to fullscreen
14:44:40 - DEBUG   - normcap:183 - [QT] qtwarningmsg - qsystemtrayicon::setvisible: no icon set
14:44:40 - DEBUG   - normcap.ocr.tesseract:24 - Executing '/tmp/.mount_NormCaRbCOZl/usr/bin/tesseract --list-langs --tessdata-dir /home/xxxxx/.config/normcap/tessdata'
14:44:40 - DEBUG   - normcap.ocr.tesseract:37 - Tesseract command output: List of available languages in "/home/xxxxx/.config/normcap/tessdata/" (1): ¬ eng ¬
14:44:49 - DEBUG   - normcap.gui.tray:350 - Hide 1 window
14:44:49 - INFO    - normcap.gui.tray:242 - Crop image to region (66, 480, 117, 525)
14:44:49 - DEBUG   - normcap.gui.utils:22 - Save debug image as /tmp/normcap/2024-05-19_12-44-49_cropped.png
14:44:49 - DEBUG   - normcap.gui.tray:267 - Start OCR
14:44:49 - DEBUG   - normcap.ocr.enhance:84 - Scale image x2
14:44:49 - DEBUG   - normcap.ocr.enhance:57 - Pad image by 80px
14:44:49 - DEBUG   - normcap.ocr.recognize:34 - Run Tesseract on image of size (264, 252) with args:
TessArgs(tessdata_path=PosixPath('/home/xxxxx/.config/normcap/tessdata'), lang='eng', oem=<OEM.DEFAULT: 3>, psm=<PSM.AUTO: 3>)
14:44:49 - DEBUG   - normcap.ocr.tesseract:24 - Executing '/tmp/.mount_NormCaRbCOZl/usr/bin/tesseract /tmp/tmp30y8a5wn/normcap_tesseract_input.png /tmp/tmp30y8a5wn/normcap_tesseract_input.png -c tessedit_create_tsv=1 -l eng --oem 3 --psm 3 --tessdata-dir /home/xxxxx/.config/normcap/tessdata -c tessedit_write_images=1 -c tessedit_dump_pageseg_images=1'
14:44:49 - DEBUG   - normcap.ocr.tesseract:37 - Tesseract command output: 
14:44:49 - DEBUG   - normcap.ocr.tesseract:67 - Skip moving file to temp dir, it does not exist: /tmp/tmp30y8a5wn/normcap_tesseract_input.png.png_debug.pdf
14:44:49 - DEBUG   - normcap.ocr.recognize:43 - OCR result:
OcrResult(tess_args=TessArgs(tessdata_path=PosixPath('/home/xxxxx/.config/normcap/tessdata'), lang='eng', oem=<OEM.DEFAULT: 3>, psm=<PSM.AUTO: 3>), words=[{'level': 5, 'page_num': 1, 'block_num': 1, 'par_num': 1, 'line_num': 1, 'word_num': 1, 'left': 102, 'top': 116, 'width': 60, 'height': 18, 'conf': 96.332726, 'text': 'test'}], image=<PySide6.QtGui.QImage(QSize(264, 252),format=QImage::Format_RGB32,depth=32,devicePixelRatio=1,bytesPerLine=1056,sizeInBytes=266112) at 0x7f1597dc7bc0>, transformer_scores={}, parsed='')
14:44:49 - DEBUG   - normcap.gui.utils:22 - Save debug image as /tmp/normcap/2024-05-19_12-44-49_enhanced.png
14:44:49 - INFO    - normcap.gui.tray:285 - Text from OCR:
test
14:44:49 - DEBUG   - normcap.gui.tray:328 - Copy text to clipboard
14:44:49 - DEBUG   - normcap.clipboard.handlers.windll:187 - normcap.clipboard.handlers.windll is incompatible on non-Windows systems
14:44:49 - DEBUG   - normcap.clipboard.handlers.pbcopy:23 - normcap.clipboard.handlers.pbcopy is incompatible on non-macOS systems
14:44:49 - DEBUG   - normcap.clipboard.handlers.qtclipboard:38 - normcap.clipboard.handlers.qtclipboard is compatible
14:44:49 - DEBUG   - normcap.clipboard.handlers.wlclipboard:34 - normcap.clipboard.handlers.wlclipboard is not compatible on non-Linux systems and on Linux w/o Wayland
14:44:49 - DEBUG   - normcap.clipboard.handlers.xsel:36 - normcap.clipboard.handlers.xsel is compatible
14:44:49 - DEBUG   - normcap.clipboard.handlers.xclip:42 - normcap.clipboard.handlers.xclip is compatible
14:44:49 - DEBUG   - normcap.clipboard.main:73 - Compatible clipboard handlers: ['QT', 'XSEL', 'XCLIP']
14:44:49 - DEBUG   - normcap.clipboard.handlers.qtclipboard:43 - normcap.clipboard.handlers.qtclipboard requires no dependencies
14:44:49 - DEBUG   - normcap.clipboard.handlers.xsel:45 - normcap.clipboard.handlers.xsel dependencies are installed (/tmp/.mount_NormCaRbCOZl/usr/bin/xsel)
14:44:49 - DEBUG   - normcap.clipboard.handlers.xclip:51 - normcap.clipboard.handlers.xclip dependencies are installed (/tmp/.mount_NormCaRbCOZl/usr/bin/xclip)
14:44:49 - DEBUG   - normcap.clipboard.main:80 - Available clipboard handlers: ['QT', 'XSEL', 'XCLIP']
14:44:49 - DEBUG   - normcap.clipboard.handlers.qtclipboard:38 - normcap.clipboard.handlers.qtclipboard is compatible
14:44:49 - INFO    - normcap.clipboard.main:35 - Text copied to clipboard using QT
14:44:49 - DEBUG   - normcap.gui.notification:173 - Send notification via QT
/tmp/.mount_NormCaRbCOZl/AppRun: line 11:  9082 Segmentation fault      (core dumped) "${APPDIR}/usr/python/bin/python3" -u -s -X utf8 -c "import runpy, sys; sys.path.pop(0); runpy.run_module('${BRIEFCASE_MAIN_MODULE}', run_name='__main__', alter_sys=True)" "$@"