koreader / koreader

An ebook reader application supporting PDF, DjVu, EPUB, FB2 and many more formats, running on Cervantes, Kindle, Kobo, PocketBook and Android devices
http://koreader.rocks/
GNU Affero General Public License v3.0
15.82k stars 1.23k forks source link

Segfault on Restart / exit #11371

Closed hasezoey closed 6 months ago

hasezoey commented 6 months ago

Issue

koreader on linux (wayland / xwayland) seems to segfault on exit and so prevent the "restart" option from working, but otherwise not really impact how it works

Steps to reproduce

  1. start koreader
  2. try to exit koreader (via window decorations, or via menu Exit -> Exit or menu Exit -> Restart KOReader)
crash.log (if applicable)
crash.log ``` --------------------------------------------- launching... _ _____ ____ _ | |/ / _ \| _ \ ___ __ _ __| | ___ _ __ | ' / | | | |_) / _ \/ _` |/ _` |/ _ \ '__| | . \ |_| | _ < __/ (_| | (_| | __/ | |_|\_\___/|_| \_\___|\__,_|\__,_|\___|_| It's a scroll... It's a codex... It's KOReader! [*] Current time: 01/16/24-13:18:44 [*] Version: v2024.01-30-g3b129e2ad_2024-01-16 ffi.load: libs/libutf8proc.so.3 ffi.load: blitbuffer ffi.load: SDL2 01/16/24-13:18:44 DEBUG fts: Preferred MONOTONIC clock source is CLOCK_MONOTONIC 01/16/24-13:18:44 DEBUG fts: Preferred REALTIME clock source is CLOCK_REALTIME 01/16/24-13:18:44 DEBUG fts: BOOTTIME clock source is supported ffi.load: SDL2 Starting SDL in /mnt/projects/android/koreader/base/build/x86_64-pc-linux-gnu-debug/ 01/16/24-13:18:44 DEBUG refresh on logical rectangle 540x720+0+0 ffi.load: libs/liblodepng.so 01/16/24-13:18:44 INFO initializing for device Emulator 01/16/24-13:18:44 INFO framebuffer resolution: { h = 720, w = 540 } --[[table: 0x7fd1de38e3c8]] ffi.load: libs/libmupdf.so ffi.load: libs/libwrap-mupdf.so ffi.load: sqlite3 ffi.load: libs/libfreetype.so.6 ffi.load: libs/libharfbuzz.so.0 ffi.load: libs/libzstd.so.1 01/16/24-13:18:45 DEBUG FontList registered: Noto Naskh Arabic 01/16/24-13:18:45 DEBUG FontList registered: Noto Sans 01/16/24-13:18:45 DEBUG FontList registered: Noto Serif 01/16/24-13:18:45 DEBUG FontList registered: Nimbus Mono 01/16/24-13:18:45 DEBUG FontList registered: Nimbus Roman No9 L 01/16/24-13:18:45 DEBUG FontList registered: Nimbus Sans L 01/16/24-13:18:45 DEBUG FontList registered: Noto Sans Arabic UI 01/16/24-13:18:45 DEBUG FontList registered: NotoSans Nerd Font 01/16/24-13:18:45 DEBUG FontList registered: FreeSerif 01/16/24-13:18:45 DEBUG FontList registered: FreeSans 01/16/24-13:18:45 DEBUG FontList registered: Noto Sans Devanagari UI 01/16/24-13:18:45 DEBUG FontList registered: Noto Sans CJK SC 01/16/24-13:18:45 DEBUG FontList registered: Standard Symbols L 01/16/24-13:18:45 DEBUG FontList registered: Noto Sans Bengali UI 01/16/24-13:18:45 DEBUG FontList registered: Droid Sans Mono 01/16/24-13:18:45 DEBUG FontList registered: Dingbats 01/16/24-13:18:45 DEBUG Found font: NotoSans-Regular.ttf in ./fonts/noto/NotoSans-Regular.ttf 01/16/24-13:18:45 DEBUG Found font: NotoSans-Bold.ttf in ./fonts/noto/NotoSans-Bold.ttf 01/16/24-13:18:45 DEBUG Found font: NotoSans-Regular.ttf in ./fonts/noto/NotoSans-Regular.ttf 01/16/24-13:18:45 DEBUG Found font: NotoSans-Regular.ttf in ./fonts/noto/NotoSans-Regular.ttf 01/16/24-13:18:45 DEBUG Found font: NotoSans-Regular.ttf in ./fonts/noto/NotoSans-Regular.ttf 01/16/24-13:18:45 DEBUG Allocating a 512MB budget for the global document cache 01/16/24-13:18:45 DEBUG Found font: NotoSans-Bold.ttf in ./fonts/noto/NotoSans-Bold.ttf 01/16/24-13:18:45 DEBUG Found font: DroidSansMono.ttf in ./fonts/droid/DroidSansMono.ttf 01/16/24-13:18:45 DEBUG ReadCollection: reading from collection file 01/16/24-13:18:45 DEBUG ImageWidget: _render'ing resources/icons/mdlight/home.svg 36 36 01/16/24-13:18:45 DEBUG renderSVG resources/icons/mdlight/home.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:45 DEBUG cache image|resources/icons/mdlight/home.svg|36|36false 01/16/24-13:18:45 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:45 DEBUG ImageWidget: _render'ing resources/icons/mdlight/plus.svg 36 36 01/16/24-13:18:45 DEBUG renderSVG resources/icons/mdlight/plus.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:45 DEBUG cache image|resources/icons/mdlight/plus.svg|36|36false 01/16/24-13:18:45 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:45 DEBUG _refresh: Enqueued ui update for region 0 0 540 72 dithering: false 01/16/24-13:18:45 DEBUG setDirty ui from widget nil w/ region 0 0 540 72 dithering: nil 01/16/24-13:18:45 DEBUG ImageWidget: _render'ing resources/icons/mdlight/close.svg 22 22 01/16/24-13:18:45 DEBUG renderSVG resources/icons/mdlight/close.svg 0.91666666666667 24 24 > 22 22 0 0 01/16/24-13:18:45 DEBUG cache image|resources/icons/mdlight/close.svg|22|22false 01/16/24-13:18:45 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:45 DEBUG ImageWidget: _render'ing resources/icons/mdlight/chevron.left.svg 36 36 01/16/24-13:18:45 DEBUG renderSVG resources/icons/mdlight/chevron.left.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:45 DEBUG cache image|resources/icons/mdlight/chevron.left.svg|36|36false 01/16/24-13:18:45 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:45 DEBUG ImageWidget: _render'ing resources/icons/mdlight/chevron.right.svg 36 36 01/16/24-13:18:45 DEBUG renderSVG resources/icons/mdlight/chevron.right.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:45 DEBUG cache image|resources/icons/mdlight/chevron.right.svg|36|36false 01/16/24-13:18:45 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:45 DEBUG ImageWidget: _render'ing resources/icons/mdlight/chevron.first.svg 36 36 01/16/24-13:18:45 DEBUG renderSVG resources/icons/mdlight/chevron.first.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:45 DEBUG cache image|resources/icons/mdlight/chevron.first.svg|36|36false 01/16/24-13:18:45 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:45 DEBUG ImageWidget: _render'ing resources/icons/mdlight/chevron.last.svg 36 36 01/16/24-13:18:45 DEBUG renderSVG resources/icons/mdlight/chevron.last.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:45 DEBUG cache image|resources/icons/mdlight/chevron.last.svg|36|36false 01/16/24-13:18:45 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:45 DEBUG ImageWidget: _render'ing resources/icons/mdlight/back.top.svg 36 36 01/16/24-13:18:45 DEBUG renderSVG resources/icons/mdlight/back.top.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:45 DEBUG cache image|resources/icons/mdlight/back.top.svg|36|36false 01/16/24-13:18:45 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:45 DEBUG Found font: DroidSansMono.ttf in ./fonts/droid/DroidSansMono.ttf 01/16/24-13:18:45 DEBUG Found font: NotoSansCJKsc-Regular.otf in ./fonts/noto/NotoSansCJKsc-Regular.otf 01/16/24-13:18:45 DEBUG Found font: NotoSans-Bold.ttf in ./fonts/noto/NotoSans-Bold.ttf 01/16/24-13:18:45 DEBUG FocusManager: Move focus position to: 1 , 1 01/16/24-13:18:45 DEBUG _refresh: Enqueued ui update for region 0 0 540 72 dithering: false 01/16/24-13:18:45 DEBUG setDirty ui from widget table: 0x7fd1c75f4ac8 w/ region 0 0 540 71 dithering: nil 01/16/24-13:18:45 DEBUG FocusManager: Move focus position to: 1 , 4 01/16/24-13:18:45 DEBUG setDirty via a func from widget table: 0x7fd1c75f4ac8 01/16/24-13:18:45 DEBUG FocusManager: Move focus position to: 1 , 4 01/16/24-13:18:45 DEBUG Getting list of dictionaries 01/16/24-13:18:45 DEBUG found 0 dictionaries 01/16/24-13:18:45 INFO Loading plugins from directory: plugins 01/16/24-13:18:45 DEBUG Plugin plugins/SSH.koplugin/main.lua has been disabled. 01/16/24-13:18:45 DEBUG Plugin plugins/autofrontlight.koplugin/main.lua has been disabled. 01/16/24-13:18:45 DEBUG Plugin plugins/autostandby.koplugin/main.lua has been disabled. 01/16/24-13:18:45 DEBUG BackgroundRunnerWidget: no job, not running @ 1705407525 01/16/24-13:18:45 DEBUG Plugin plugins/hello.koplugin/main.lua has been disabled. 01/16/24-13:18:45 DEBUG Plugin plugins/timesync.koplugin/main.lua has been disabled. 01/16/24-13:18:45 DEBUG Plugin plugins/externalkeyboard.koplugin/main.lua has been disabled. 01/16/24-13:18:45 DEBUG japanese.koplugin deinflector: loaded inflection table with 36 rules and 569 variants 01/16/24-13:18:45 DEBUG Plugin plugins/patchmanagement.koplugin/main.lua has been disabled. 01/16/24-13:18:45 DEBUG Found font: NotoSans-Regular.ttf in ./fonts/noto/NotoSans-Regular.ttf 01/16/24-13:18:45 DEBUG Found font: NotoSans-Italic.ttf in ./fonts/noto/NotoSans-Italic.ttf 01/16/24-13:18:45 DEBUG FM loaded plugin archiveviewer at plugins/archiveviewer.koplugin 01/16/24-13:18:45 DEBUG FM loaded plugin autodim at plugins/autodim.koplugin 01/16/24-13:18:45 DEBUG AutoSuspend: init 01/16/24-13:18:45 DEBUG AutoSuspend: start suspend/shutdown timer at 9276.277156 01/16/24-13:18:45 DEBUG AutoSuspend: scheduling next suspend check in 900 01/16/24-13:18:45 DEBUG AutoSuspend: scheduling next shutdown check in 259200 01/16/24-13:18:45 DEBUG FM loaded plugin autosuspend at plugins/autosuspend.koplugin 01/16/24-13:18:45 DEBUG AutoWarmth: scheduleMidnightUpdate 01/16/24-13:18:45 DEBUG FM loaded plugin autowarmth at plugins/autowarmth.koplugin 01/16/24-13:18:45 DEBUG FM loaded plugin backgroundrunner at plugins/backgroundrunner.koplugin 01/16/24-13:18:45 DEBUG FM loaded plugin batterystat at plugins/batterystat.koplugin 01/16/24-13:18:45 DEBUG FM loaded plugin bookshortcuts at plugins/bookshortcuts.koplugin 01/16/24-13:18:45 DEBUG FM loaded plugin calibre at plugins/calibre.koplugin 01/16/24-13:18:45 DEBUG CoverBrowser: setting FileManager display mode to: mosaic_image 01/16/24-13:18:46 DEBUG CoverBrowser: setting History display mode to: mosaic_image 01/16/24-13:18:46 DEBUG CoverBrowser: setting Collection display mode to: classic 01/16/24-13:18:46 DEBUG FM loaded plugin coverbrowser at plugins/coverbrowser.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin docsettingtweak at plugins/docsettingtweak.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin exporter at plugins/exporter.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin gestures at plugins/gestures.koplugin 01/16/24-13:18:46 DEBUG language support: registering japanese plugin 01/16/24-13:18:46 DEBUG FM loaded plugin japanese at plugins/japanese.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin keepalive at plugins/keepalive.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin movetoarchive at plugins/movetoarchive.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin newsdownloader at plugins/newsdownloader.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin opds at plugins/opds.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin perceptionexpander at plugins/perceptionexpander.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin profiles at plugins/profiles.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin qrclipboard at plugins/qrclipboard.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin readtimer at plugins/readtimer.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin statistics at plugins/statistics.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin systemstat at plugins/systemstat.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin terminal at plugins/terminal.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin texteditor at plugins/texteditor.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin vocabbuilder at plugins/vocabbuilder.koplugin 01/16/24-13:18:46 DEBUG FM loaded plugin wallabag at plugins/wallabag.koplugin 01/16/24-13:18:46 DEBUG Spinning up new FileManager instance table: 0x7fd1c75f4ac8 01/16/24-13:18:46 DEBUG show widget: table: 0x7fd1c75f4ac8 01/16/24-13:18:46 DEBUG setDirty nil from widget table: 0x7fd1c75f4ac8 w/ NO region; dithering: nil 01/16/24-13:18:46 DEBUG AutoSuspend: onNetworkConnected 01/16/24-13:18:46 DEBUG NetworkListener: onNetworkConnected 01/16/24-13:18:46 DEBUG Found font: NotoSansArabicUI-Bold.ttf in ./fonts/noto/NotoSansArabicUI-Bold.ttf 01/16/24-13:18:46 DEBUG DocSettings: data is read from /home/hasezoey/Downloads/test/i-shall-survive-using-potions-volume-8.sdr/metadata.epub.lua 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing data nil nil 01/16/24-13:18:46 DEBUG ImageWidget: scaling by 0.9290780141844 01/16/24-13:18:46 DEBUG RenderImage:scaleBlitBuffer: scaling 01/16/24-13:18:46 DEBUG DocSettings: data is read from /home/hasezoey/Downloads/test/i-shall-survive-using-potions-volume-7.sdr/metadata.epub.lua 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing data nil nil 01/16/24-13:18:46 DEBUG ImageWidget: scaling by 0.9290780141844 01/16/24-13:18:46 DEBUG RenderImage:scaleBlitBuffer: scaling 01/16/24-13:18:46 DEBUG DocSettings: data is read from /home/hasezoey/Downloads/test/i-shall-survive-using-potions-volume-6.sdr/metadata.epub.lua 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing data nil nil 01/16/24-13:18:46 DEBUG ImageWidget: scaling by 0.9290780141844 01/16/24-13:18:46 DEBUG RenderImage:scaleBlitBuffer: scaling 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing data nil nil 01/16/24-13:18:46 DEBUG DocSettings: data is read from /home/hasezoey/Downloads/test/i-shall-survive-using-potions-volume-4.sdr/metadata.epub.lua 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing data nil nil 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing data nil nil 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing data nil nil 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing data nil nil 01/16/24-13:18:46 DEBUG FocusManager: Move focus position to: 1 , 1 01/16/24-13:18:46 DEBUG _refresh: Enqueued ui update for region 0 0 540 72 dithering: false 01/16/24-13:18:46 DEBUG setDirty ui from widget table: 0x7fd1c75f4ac8 w/ region 0 0 540 71 dithering: nil 01/16/24-13:18:46 DEBUG setDirty via a func from widget table: 0x7fd1c75f4ac8 01/16/24-13:18:46 DEBUG FocusManager: Move focus position to: 1 , 4 01/16/24-13:18:46 DEBUG _refresh: Enqueued ui update for region 0 0 540 72 dithering: false 01/16/24-13:18:46 DEBUG setDirty ui from widget nil w/ region 0 0 540 72 dithering: nil 01/16/24-13:18:46 DEBUG painting widget: table: 0x7fd1c75f4ac8 01/16/24-13:18:46 DEBUG Found font: NotoSansCJKsc-Regular.otf in ./fonts/noto/NotoSansCJKsc-Regular.otf 01/16/24-13:18:46 DEBUG Found font: NotoSansCJKsc-Regular.otf in ./fonts/noto/NotoSansCJKsc-Regular.otf 01/16/24-13:18:46 DEBUG blitFrom 5 5 0 0 36 36 01/16/24-13:18:46 DEBUG blitFrom 499 5 0 0 36 36 01/16/24-13:18:46 DEBUG blitFrom 204 82 0 0 131 186 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing resources/icons/mdlight/dogear.reading.svg 21 21 01/16/24-13:18:46 DEBUG renderSVG resources/icons/mdlight/dogear.reading.svg 0.4375 48 48 > 21 21 0 0 01/16/24-13:18:46 DEBUG cache image|resources/icons/mdlight/dogear.reading.svg|21|21false 01/16/24-13:18:46 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:46 DEBUG blitFrom 315 249 0 0 21 21 01/16/24-13:18:46 DEBUG blitFrom 381 82 0 0 131 186 01/16/24-13:18:46 DEBUG blitFrom 492 249 0 0 21 21 01/16/24-13:18:46 DEBUG blitFrom 27 281 0 0 131 186 01/16/24-13:18:46 DEBUG blitFrom 138 448 0 0 21 21 01/16/24-13:18:46 DEBUG blitFrom 204 281 0 0 131 187 01/16/24-13:18:46 DEBUG blitFrom 381 281 0 0 131 187 01/16/24-13:18:46 DEBUG ImageWidget: _render'ing resources/icons/mdlight/dogear.complete.svg 21 21 01/16/24-13:18:46 DEBUG renderSVG resources/icons/mdlight/dogear.complete.svg 0.4375 48 48 > 21 21 0 0 01/16/24-13:18:46 DEBUG cache image|resources/icons/mdlight/dogear.complete.svg|21|21true 01/16/24-13:18:46 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:46 DEBUG blitFrom 492 448 0 0 21 21 01/16/24-13:18:46 DEBUG blitFrom 27 480 0 0 131 187 01/16/24-13:18:46 DEBUG blitFrom 204 480 0 0 132 187 01/16/24-13:18:46 DEBUG blitFrom 380 480 0 0 133 187 01/16/24-13:18:46 DEBUG blitFrom 85 682 0 0 36 36 01/16/24-13:18:46 DEBUG blitFrom 154 682 0 0 36 36 01/16/24-13:18:46 DEBUG blitFrom 350 682 0 0 36 36 01/16/24-13:18:46 DEBUG blitFrom 419 682 0 0 36 36 01/16/24-13:18:46 DEBUG _repaint: it was dithered, infecting the refresh queue 01/16/24-13:18:46 DEBUG update_dither: Update dither hint false to true 01/16/24-13:18:46 DEBUG _refresh: Enqueued ui update for region 0 0 540 720 dithering: true 01/16/24-13:18:46 DEBUG _refresh: Enqueued ui update for region 0 0 540 720 dithering: true 01/16/24-13:18:46 DEBUG triggering refresh { mode = "ui", region = "540x720+0+0" } --[[table: 0x7fd1c53d3238]] 01/16/24-13:18:46 DEBUG refresh on logical rectangle 540x720+0+0 01/16/24-13:18:46 DEBUG input event => type: 83 (EV_SDL), code: 4, value: cdata: 0x7fd1cca309c8, time: 9277.734203 01/16/24-13:18:47 DEBUG input event => type: 3 (EV_ABS), code: 47 (ABS_MT_SLOT), value: 0, time: 9279.154209 01/16/24-13:18:47 DEBUG input event => type: 3 (EV_ABS), code: 57 (ABS_MT_TRACKING_ID), value: 0, time: 9279.154209 01/16/24-13:18:47 DEBUG input event => type: 3 (EV_ABS), code: 53 (ABS_MT_POSITION_X), value: 365, time: 9279.154209 01/16/24-13:18:47 DEBUG input event => type: 3 (EV_ABS), code: 54 (ABS_MT_POSITION_Y), value: 12, time: 9279.154209 01/16/24-13:18:47 DEBUG input event => type: 0 (EV_SYN), code: 0 (SYN_REPORT), value: 0, time: 9279.154209 01/16/24-13:18:47 DEBUG GestureDetector:probeClockSource: Touch event timestamps appear to use CLOCK_MONOTONIC 01/16/24-13:18:47 DEBUG slot 0 in tap state... 01/16/24-13:18:47 DEBUG set up hold timer 01/16/24-13:18:47 DEBUG AutoSuspend: onInputEvent .. truncated input events (too long for github) 01/16/24-13:18:47 DEBUG input event => type: 3 (EV_ABS), code: 47 (ABS_MT_SLOT), value: 0, time: 9279.337543 01/16/24-13:18:47 DEBUG input event => type: 3 (EV_ABS), code: 57 (ABS_MT_TRACKING_ID), value: -1, time: 9279.337543 01/16/24-13:18:47 DEBUG input event => type: 3 (EV_ABS), code: 53 (ABS_MT_POSITION_X), value: 354, time: 9279.337543 01/16/24-13:18:47 DEBUG input event => type: 3 (EV_ABS), code: 54 (ABS_MT_POSITION_Y), value: 89, time: 9279.337543 01/16/24-13:18:47 DEBUG input event => type: 0 (EV_SYN), code: 0 (SYN_REPORT), value: 0, time: 9279.337543 01/16/24-13:18:47 DEBUG slot 0 in pan state... 01/16/24-13:18:47 DEBUG Contact:handleSwipe: swipe south 77.78174593052 detected 01/16/24-13:18:47 DEBUG AutoSuspend: onInputEvent 01/16/24-13:18:47 DEBUG ImageWidget: _render'ing resources/icons/mdlight/appbar.filebrowser.svg 36 36 01/16/24-13:18:47 DEBUG renderSVG resources/icons/mdlight/appbar.filebrowser.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:47 DEBUG cache image|resources/icons/mdlight/appbar.filebrowser.svg|36|36false 01/16/24-13:18:47 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:47 DEBUG ImageWidget: _render'ing resources/icons/mdlight/appbar.settings.svg 36 36 01/16/24-13:18:47 DEBUG renderSVG resources/icons/mdlight/appbar.settings.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:47 DEBUG cache image|resources/icons/mdlight/appbar.settings.svg|36|36false 01/16/24-13:18:47 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:47 DEBUG ImageWidget: _render'ing resources/icons/mdlight/appbar.tools.svg 36 36 01/16/24-13:18:47 DEBUG renderSVG resources/icons/mdlight/appbar.tools.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:47 DEBUG cache image|resources/icons/mdlight/appbar.tools.svg|36|36false 01/16/24-13:18:47 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:47 DEBUG ImageWidget: _render'ing resources/icons/mdlight/appbar.search.svg 36 36 01/16/24-13:18:47 DEBUG renderSVG resources/icons/mdlight/appbar.search.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:47 DEBUG cache image|resources/icons/mdlight/appbar.search.svg|36|36false 01/16/24-13:18:47 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:47 DEBUG ImageWidget: _render'ing resources/icons/mdlight/appbar.menu.svg 36 36 01/16/24-13:18:47 DEBUG renderSVG resources/icons/mdlight/appbar.menu.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:47 DEBUG cache image|resources/icons/mdlight/appbar.menu.svg|36|36false 01/16/24-13:18:47 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:47 DEBUG ImageWidget: _render'ing resources/icons/mdlight/chevron.left.svg 36 36 01/16/24-13:18:47 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:47 DEBUG ImageWidget: _render'ing resources/icons/mdlight/chevron.right.svg 36 36 01/16/24-13:18:47 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:47 DEBUG ImageWidget: _render'ing resources/icons/mdlight/chevron.up.svg 36 36 01/16/24-13:18:47 DEBUG renderSVG resources/icons/mdlight/chevron.up.svg 0.75 48 48 > 36 36 0 0 01/16/24-13:18:47 DEBUG cache image|resources/icons/mdlight/chevron.up.svg|36|36false 01/16/24-13:18:47 DEBUG ImageWidget: initial offsets 0 0 01/16/24-13:18:47 DEBUG Found font: NotoSansCJKsc-Regular.otf in ./fonts/noto/NotoSansCJKsc-Regular.otf 01/16/24-13:18:47 DEBUG Found font: NotoSansArabicUI-Regular.ttf in ./fonts/noto/NotoSansArabicUI-Regular.ttf 01/16/24-13:18:47 DEBUG Found font: NotoSansDevanagariUI-Regular.ttf in ./fonts/noto/NotoSansDevanagariUI-Regular.ttf 01/16/24-13:18:47 DEBUG Found font: NotoSansBengaliUI-Regular.ttf in ./fonts/noto/NotoSansBengaliUI-Regular.ttf 01/16/24-13:18:47 DEBUG Found font: NotoSansArabicUI-Regular.ttf in ./fonts/noto/NotoSansArabicUI-Regular.ttf 01/16/24-13:18:47 DEBUG Found font: NotoSansDevanagariUI-Regular.ttf in ./fonts/noto/NotoSansDevanagariUI-Regular.ttf 01/16/24-13:18:47 DEBUG Found font: NotoSansBengaliUI-Regular.ttf in ./fonts/noto/NotoSansBengaliUI-Regular.ttf 01/16/24-13:18:47 DEBUG FocusManager: Move focus position to: 5 , 1 01/16/24-13:18:47 DEBUG setDirty via a func from widget table: 0x7fd1c7569770 01/16/24-13:18:47 DEBUG show widget: table: 0x7fd1c7569770 01/16/24-13:18:47 DEBUG setDirty nil from widget table: 0x7fd1c7569770 w/ NO region; dithering: nil 01/16/24-13:18:47 DEBUG painting widget: table: 0x7fd1c7569770 01/16/24-13:18:47 DEBUG blitFrom 15 7 0 0 36 36 01/16/24-13:18:47 DEBUG blitFrom 83 7 0 0 36 36 01/16/24-13:18:47 DEBUG blitFrom 151 7 0 0 36 36 01/16/24-13:18:47 DEBUG blitFrom 219 7 0 0 36 36 01/16/24-13:18:47 DEBUG blitFrom 489 7 0 0 36 36 01/16/24-13:18:47 DEBUG blitFrom 26 279 0 0 36 36 01/16/24-13:18:47 DEBUG _refresh: Enqueued flashui update for region 0 0 540 323 dithering: false 01/16/24-13:18:47 DEBUG triggering refresh { mode = "flashui", region = "540x323+0+0" } --[[table: 0x7fd1c74206d8]] 01/16/24-13:18:47 DEBUG refresh on logical rectangle 540x323+0+0 01/16/24-13:18:48 DEBUG input event => type: 3 (EV_ABS), code: 47 (ABS_MT_SLOT), value: 0, time: 9280.264214 01/16/24-13:18:48 DEBUG input event => type: 3 (EV_ABS), code: 57 (ABS_MT_TRACKING_ID), value: 0, time: 9280.264214 01/16/24-13:18:48 DEBUG input event => type: 3 (EV_ABS), code: 53 (ABS_MT_POSITION_X), value: 59, time: 9280.264214 01/16/24-13:18:48 DEBUG input event => type: 3 (EV_ABS), code: 54 (ABS_MT_POSITION_Y), value: 248, time: 9280.264214 01/16/24-13:18:48 DEBUG input event => type: 0 (EV_SYN), code: 0 (SYN_REPORT), value: 0, time: 9280.264214 01/16/24-13:18:48 DEBUG slot 0 in tap state... 01/16/24-13:18:48 DEBUG set up hold timer 01/16/24-13:18:48 DEBUG AutoSuspend: onInputEvent 01/16/24-13:18:48 DEBUG input event => type: 3 (EV_ABS), code: 47 (ABS_MT_SLOT), value: 0, time: 9280.337548 01/16/24-13:18:48 DEBUG input event => type: 3 (EV_ABS), code: 57 (ABS_MT_TRACKING_ID), value: -1, time: 9280.337548 01/16/24-13:18:48 DEBUG input event => type: 3 (EV_ABS), code: 53 (ABS_MT_POSITION_X), value: 59, time: 9280.337548 01/16/24-13:18:48 DEBUG input event => type: 3 (EV_ABS), code: 54 (ABS_MT_POSITION_Y), value: 248, time: 9280.337548 01/16/24-13:18:48 DEBUG input event => type: 0 (EV_SYN), code: 0 (SYN_REPORT), value: 0, time: 9280.337548 01/16/24-13:18:48 DEBUG slot 0 in tap state... 01/16/24-13:18:48 DEBUG Contact:handleDoubleTap: single tap detected @ 59 248 01/16/24-13:18:48 DEBUG AutoSuspend: onInputEvent 01/16/24-13:18:48 DEBUG Explicit widgetInvert: table: 0x7fd1c6ae5ef8 @ 5 232 01/16/24-13:18:48 DEBUG _refresh: Enqueued fast update for region 5 232 530 42 dithering: false 01/16/24-13:18:48 DEBUG setDirty fast from widget nil w/ region 5 232 530 42 dithering: nil 01/16/24-13:18:48 DEBUG triggering refresh { mode = "fast", region = "530x42+5+232" } --[[table: 0x7fd1c49b3d18]] 01/16/24-13:18:48 DEBUG refresh on logical rectangle 530x42+5+232 01/16/24-13:18:48 DEBUG FocusManager: Move focus position to: 5 , 1 01/16/24-13:18:48 DEBUG setDirty on all widgets: found a dithered widget, infecting the refresh queue 01/16/24-13:18:48 DEBUG setDirty via a func from widget all 01/16/24-13:18:48 DEBUG painting widget: table: 0x7fd1c75f4ac8 01/16/24-13:18:48 DEBUG blitFrom 5 5 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 499 5 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 204 82 0 0 131 186 01/16/24-13:18:48 DEBUG blitFrom 315 249 0 0 21 21 01/16/24-13:18:48 DEBUG blitFrom 381 82 0 0 131 186 01/16/24-13:18:48 DEBUG blitFrom 492 249 0 0 21 21 01/16/24-13:18:48 DEBUG blitFrom 27 281 0 0 131 186 01/16/24-13:18:48 DEBUG blitFrom 138 448 0 0 21 21 01/16/24-13:18:48 DEBUG blitFrom 204 281 0 0 131 187 01/16/24-13:18:48 DEBUG blitFrom 381 281 0 0 131 187 01/16/24-13:18:48 DEBUG blitFrom 492 448 0 0 21 21 01/16/24-13:18:48 DEBUG blitFrom 27 480 0 0 131 187 01/16/24-13:18:48 DEBUG blitFrom 204 480 0 0 132 187 01/16/24-13:18:48 DEBUG blitFrom 380 480 0 0 133 187 01/16/24-13:18:48 DEBUG blitFrom 85 682 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 154 682 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 350 682 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 419 682 0 0 36 36 01/16/24-13:18:48 DEBUG _repaint: it was dithered, infecting the refresh queue 01/16/24-13:18:48 DEBUG painting widget: table: 0x7fd1c7569770 01/16/24-13:18:48 DEBUG blitFrom 15 7 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 83 7 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 151 7 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 219 7 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 489 7 0 0 36 36 01/16/24-13:18:48 DEBUG blitFrom 26 278 0 0 36 36 01/16/24-13:18:48 DEBUG _refresh: Enqueued ui update for region 0 0 540 323 dithering: true 01/16/24-13:18:48 DEBUG triggering refresh { mode = "ui", region = "540x323+0+0" } --[[table: 0x7fd1cedd6580]] 01/16/24-13:18:48 DEBUG refresh on logical rectangle 540x323+0+0 01/16/24-13:18:49 DEBUG input event => type: 3 (EV_ABS), code: 47 (ABS_MT_SLOT), value: 0, time: 9281.050884 01/16/24-13:18:49 DEBUG input event => type: 3 (EV_ABS), code: 57 (ABS_MT_TRACKING_ID), value: 0, time: 9281.050884 01/16/24-13:18:49 DEBUG input event => type: 3 (EV_ABS), code: 53 (ABS_MT_POSITION_X), value: 59, time: 9281.050884 01/16/24-13:18:49 DEBUG input event => type: 3 (EV_ABS), code: 54 (ABS_MT_POSITION_Y), value: 249, time: 9281.050884 01/16/24-13:18:49 DEBUG input event => type: 0 (EV_SYN), code: 0 (SYN_REPORT), value: 0, time: 9281.050884 01/16/24-13:18:49 DEBUG slot 0 in tap state... 01/16/24-13:18:49 DEBUG set up hold timer 01/16/24-13:18:49 DEBUG AutoSuspend: onInputEvent 01/16/24-13:18:49 DEBUG input event => type: 3 (EV_ABS), code: 47 (ABS_MT_SLOT), value: 0, time: 9281.130884 01/16/24-13:18:49 DEBUG input event => type: 3 (EV_ABS), code: 57 (ABS_MT_TRACKING_ID), value: -1, time: 9281.130884 01/16/24-13:18:49 DEBUG input event => type: 3 (EV_ABS), code: 53 (ABS_MT_POSITION_X), value: 59, time: 9281.130884 01/16/24-13:18:49 DEBUG input event => type: 3 (EV_ABS), code: 54 (ABS_MT_POSITION_Y), value: 249, time: 9281.130884 01/16/24-13:18:49 DEBUG input event => type: 0 (EV_SYN), code: 0 (SYN_REPORT), value: 0, time: 9281.130884 01/16/24-13:18:49 DEBUG slot 0 in tap state... 01/16/24-13:18:49 DEBUG Contact:handleDoubleTap: single tap detected @ 59 249 01/16/24-13:18:49 DEBUG AutoSuspend: onInputEvent 01/16/24-13:18:49 DEBUG Explicit widgetInvert: table: 0x7fd1cede56f8 @ 5 231 01/16/24-13:18:49 DEBUG _refresh: Enqueued fast update for region 5 231 530 42 dithering: false 01/16/24-13:18:49 DEBUG setDirty fast from widget nil w/ region 5 231 530 42 dithering: nil 01/16/24-13:18:49 DEBUG triggering refresh { mode = "fast", region = "530x42+5+231" } --[[table: 0x7fd1ceda2268]] 01/16/24-13:18:49 DEBUG refresh on logical rectangle 530x42+5+231 01/16/24-13:18:49 DEBUG close widget: table: 0x7fd1c7569770 01/16/24-13:18:49 DEBUG _refresh: Enqueued flashui update for region 0 0 540 720 dithering: false 01/16/24-13:18:49 DEBUG setDirty flashui from widget nil w/ NO region; dithering: nil 01/16/24-13:18:49 DEBUG Lower widget table: 0x7fd1c75f4ac8 was dithered, honoring the dithering hint 01/16/24-13:18:49 DEBUG Lower widget table: 0x7fd1c75f4ac8 covers the full screen 01/16/24-13:18:49 DEBUG update_dither: Update dither hint false to true 01/16/24-13:18:49 DEBUG _refresh: Enqueued flashui update for region 0 0 540 720 dithering: true 01/16/24-13:18:49 DEBUG setDirty nil from widget table: 0x7fd1c75f4ac8 w/ NO region; dithering: true 01/16/24-13:18:49 DEBUG _refresh: Enqueued flashui update for region 0 0 540 720 dithering: true 01/16/24-13:18:49 DEBUG close filemanager 01/16/24-13:18:49 DEBUG close widget: table: 0x7fd1c75f4ac8 01/16/24-13:18:49 DEBUG CoverMenu:onCloseWidget: terminating jobs if needed 01/16/24-13:18:49 DEBUG terminating 0 subprocesses 01/16/24-13:18:49 DEBUG _refresh: Enqueued flashui update for region 0 0 540 720 dithering: true 01/16/24-13:18:49 DEBUG setDirty ui from widget nil w/ NO region; dithering: nil 01/16/24-13:18:49 DEBUG AutoSuspend: onCloseWidget 01/16/24-13:18:49 DEBUG AutoSuspend: unschedule suspend/shutdown timer 01/16/24-13:18:49 DEBUG Tearing down FileManager table: 0x7fd1c75f4ac8 01/16/24-13:18:49 DEBUG close widget: table: 0x7fd1c7569770 01/16/24-13:18:49 DEBUG update_dither: Update dither hint false to true 01/16/24-13:18:49 DEBUG triggering refresh { mode = "flashui", region = "540x720+0+0" } --[[table: 0x7fd1c4469f10]] 01/16/24-13:18:49 DEBUG refresh on logical rectangle 540x720+0+0 01/16/24-13:18:49 INFO UIManager: No dialogs left to show 01/16/24-13:18:49 INFO Tearing down UIManager with exit code: 0 ./kodev: line 772: 209914 Segmentation fault (core dumped) env EMULATE_READER_W="${screen_width}" EMULATE_READER_H="${screen_height}" EMULATE_READER_DPI="${screen_dpi}" ${KOREADER_COMMAND} /mnt/projects/android/koreader ```
GDB backtrace ```txt (gdb) bt #0 0x00007fd1ddaddf60 in ?? () #1 0x00007fd1de12f3d3 in GL_DestroyTexture (renderer=, texture=0x555d715c14b0) at /usr/src/debug/sdl2/SDL2-2.28.5/src/render/opengl/SDL_render_gl.c:1509 #2 0x00007fd1de13556c in SDL_DestroyTexture_REAL (texture=0x555d715c14b0) at /usr/src/debug/sdl2/SDL2-2.28.5/src/render/SDL_render.c:4287 #3 0x00007fd1de135763 in SDL_DestroyTexture_REAL (texture=) at /usr/src/debug/sdl2/SDL2-2.28.5/src/render/SDL_render.c:4253 #4 SDL_DestroyRenderer_REAL (renderer=0x555d70ec3ce0) at /usr/src/debug/sdl2/SDL2-2.28.5/src/render/SDL_render.c:4326 #5 SDL_DestroyRenderer_REAL (renderer=0x555d70ec3ce0) at /usr/src/debug/sdl2/SDL2-2.28.5/src/render/SDL_render.c:4295 #6 0x0000555d70a13fa9 in lj_vm_ffi_call () at buildvm_x86.dasc:2707 #7 0x0000555d70a36b68 in lj_ccall_func (L=L@entry=0x7fd1de760380, cd=) at lj_ccall.c:1187 #8 0x0000555d70a0f810 in lj_cf_ffi_meta___call (L=0x7fd1de760380) at lib_ffi.c:230 #9 0x0000555d70a11b46 in lj_BC_FUNCC () at buildvm_x86.dasc:857 #10 0x0000555d70a14316 in gc_call_finalizer (g=g@entry=0x7fd1de7603e0, L=L@entry=0x7fd1de760380, mo=mo@entry=0x7fffa3986f38, o=0x7fd1de312870) at lj_gc.c:521 #11 0x0000555d70a152de in lj_gc_finalize_cdata (L=L@entry=0x7fd1de760380) at lj_gc.c:602 #12 0x0000555d709fa466 in cpfinalize (L=0x7fd1de760380, dummy=, ud=) at lj_state.c:289 #13 0x0000555d70a11f3c in lj_vm_cpcall () at buildvm_x86.dasc:1246 #14 0x0000555d709fa845 in lua_close (L=L@entry=0x7fd1de760380) at lj_state.c:316 #15 0x0000555d70a416ed in lj_cf_os_exit (L=0x7fd1de760380) at lib_os.c:120 #16 0x0000555d70a11b46 in lj_BC_FUNCC () at buildvm_x86.dasc:857 #17 0x0000555d70a00638 in lua_pcall (L=L@entry=0x7fd1de760380, nargs=nargs@entry=1, nresults=-1, errfunc=errfunc@entry=2) at lj_api.c:1150 #18 0x0000555d709f599e in docall (L=L@entry=0x7fd1de760380, narg=narg@entry=1, clear=clear@entry=0) at luajit.c:122 #19 0x0000555d709f6215 in handle_script (L=L@entry=0x7fd1de760380, argx=argx@entry=0x7fffa3987320) at luajit.c:292 #20 0x0000555d709f68f2 in pmain (L=0x7fd1de760380) at luajit.c:550 #21 0x0000555d70a11b46 in lj_BC_FUNCC () at buildvm_x86.dasc:857 #22 0x0000555d70a0068b in lua_cpcall (L=L@entry=0x7fd1de760380, func=func@entry=0x555d709f679d , ud=ud@entry=0x0) at lj_api.c:1178 #23 0x0000555d709f69b2 in main (argc=3, argv=0x7fffa3987318) at luajit.c:581 ```
Frenzie commented 6 months ago

Just to be sure, you ran git submodule update --recursive?

hasezoey commented 6 months ago

Just to be sure, you ran git submodule update --recursive?

yes


re https://github.com/koreader/koreader/issues/11372#issuecomment-1893721479

i forgot i had SDL_VIDEODRIVER=wayland set, running with SDL_VIDEODRIVER=x11 ~5 times the segfault on exit does not occur

Frenzie commented 6 months ago

That strange. SDL is 2.28.3 or higher?

hasezoey commented 6 months ago

That strange. SDL is 2.28.3 or higher?

what path or the system sdl version?

system installed sdl:

sdl2 2.28.5-1
sdl2_image 2.8.2-1
Frenzie commented 6 months ago

The development/emulator version simply uses the one from the system, yes. If I have time I'll check later if I can repro.

NiLuJe commented 6 months ago

Maaaaybe related to the segfault(s) discussed in https://github.com/koreader/koreader-base/pull/1679?

Frenzie commented 6 months ago

No, I suspect it's https://github.com/libsdl-org/SDL/issues/8354 which will end up in 2.28.6.

Edit: pardon, didn't read well enough :-P

But regardless, I don't see how https://github.com/koreader/koreader-base/pull/1679 could relate since we're talking about Wayland vs not Wayland.

NiLuJe commented 6 months ago

I'm seeing Lua finalizers in the trace, and we've seen borked finalizers leaving a mess that SDL or the GL driver gets to pay the price for later ;).

That was something that came up during those discussions, IIRC.

Frenzie commented 6 months ago

Exclusively on Wayland.

NiLuJe commented 6 months ago

Which is potentially a red herring is what I was getting at, I guess ;).

(e.g., I seem to recall finalizer issues like that only surfacing as a crash on some GL drivers back in the day).

hugleo commented 6 months ago

Is SDL.screen a fine window? In file framebuffer_SDL2_0.lua the function framebuffer:close() call SDL.SDL.SDL_Quit() and this will cause crash with os.exit later. Add SDL_DestroyWindow for test and face the same crash.

function framebuffer:close()
    SDL.SDL.SDL_DestroyWindow(SDL.screen)
    --SDL.SDL.SDL_DestroyWindow(SDL.window)
    --SDL.SDL.SDL_Quit()
end
Frenzie commented 6 months ago

It's the same one that's used everywhere for everything, so yes.

Frenzie commented 6 months ago

I won't bother with a Wayland session right now but you could sanity check if something simple like this even works at all:

// cc bla.c -o bla $(pkg-config --cflags --libs sdl2)
#include <SDL.h>

int main()
{
  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
  {
      printf("Failed to initialize the SDL2 library\n");
      return -1;
  }

  SDL_Window *window = SDL_CreateWindow("SDL2 Window",
                                    SDL_WINDOWPOS_CENTERED,
                                    SDL_WINDOWPOS_CENTERED,
                                    680, 480,
                                    0);

  if(!window)
  {
      printf("Failed to create window\n");
      return -1;
  }

  SDL_Surface *window_surface = SDL_GetWindowSurface(window);

  if(!window_surface)
  {
      printf("Failed to get the surface from the window\n");
      return -1;
  }

  SDL_UpdateWindowSurface(window);

  SDL_Delay(5000);

  SDL_Quit();

  return 0;
}
NiLuJe commented 6 months ago

@hugleo may be on to something?

diff --git a/ffi-cdecl/SDL2_0_decl.c b/ffi-cdecl/SDL2_0_decl.c
index a9135664..41837803 100644
--- a/ffi-cdecl/SDL2_0_decl.c
+++ b/ffi-cdecl/SDL2_0_decl.c
@@ -129,6 +129,7 @@ cdecl_func(SDL_Delay)
 cdecl_func(SDL_GetCurrentDisplayMode)
 cdecl_func(SDL_EnableScreenSaver)
 cdecl_func(SDL_CreateWindow)
+cdecl_func(SDL_DestroyWindow)
 cdecl_func(SDL_GetWindowSize)
 cdecl_func(SDL_CreateRenderer)
 cdecl_func(SDL_DestroyRenderer)
diff --git a/ffi/SDL2_0.lua b/ffi/SDL2_0.lua
index 77573bf9..864ff658 100644
--- a/ffi/SDL2_0.lua
+++ b/ffi/SDL2_0.lua
@@ -132,10 +132,11 @@ function S.open(w, h, x, y)
     -- set up screen (window)
     local pos_x = tonumber(os.getenv("KOREADER_WINDOW_POS_X")) or x or SDL.SDL_WINDOWPOS_UNDEFINED
     local pos_y = tonumber(os.getenv("KOREADER_WINDOW_POS_Y")) or y or SDL.SDL_WINDOWPOS_UNDEFINED
-    S.screen = SDL.SDL_CreateWindow("KOReader",
+    S.screen = ffi.gc(SDL.SDL_CreateWindow("KOReader",
         pos_x, pos_y,
         S.win_w, S.win_h,
-        bit.bor(full_screen and SDL.SDL_WINDOW_FULLSCREEN or 0, SDL.SDL_WINDOW_RESIZABLE, SDL.SDL_WINDOW_ALLOW_HIGHDPI)
+        bit.bor(full_screen and SDL.SDL_WINDOW_FULLSCREEN or 0, SDL.SDL_WINDOW_RESIZABLE, SDL.SDL_WINDOW_ALLOW_HIGHDPI)),
+        SDL.SDL_DestroyWindow
     )
     -- For some mysterious reason, CreateWindow doesn't give a damn about the initial position, and will enforce top-left (we get an SDL_WINDOWEVENT_MOVED), so, force its hand...
     -- What's even more curious is that we still only get a single SDL_WINDOWEVENT_MOVED on startup, except that way it's at the requested coordinates...
diff --git a/ffi/SDL2_0_h.lua b/ffi/SDL2_0_h.lua
index aebf9774..ce69b80c 100644
--- a/ffi/SDL2_0_h.lua
+++ b/ffi/SDL2_0_h.lua
@@ -792,6 +792,7 @@ void SDL_Delay(Uint32) __attribute__((visibility("default")));
 int SDL_GetCurrentDisplayMode(int, SDL_DisplayMode *) __attribute__((visibility("default")));
 void SDL_EnableScreenSaver(void) __attribute__((visibility("default")));
 SDL_Window *SDL_CreateWindow(const char *, int, int, int, int, Uint32) __attribute__((visibility("default")));
+void SDL_DestroyWindow(SDL_Window *) __attribute__((visibility("default")));
 void SDL_GetWindowSize(SDL_Window *, int *, int *) __attribute__((visibility("default")));
 SDL_Renderer *SDL_CreateRenderer(SDL_Window *, int, Uint32) __attribute__((visibility("default")));
 void SDL_DestroyRenderer(SDL_Renderer *) __attribute__((visibility("default")));

Does seem to prevent a segfault on exit over here (X11).

(Or it just decided to stop crashing tonight ;D).

hasezoey commented 6 months ago

I won't bother with a Wayland session right now but you could sanity check if something simple like this even works at all:

just tested, and it goes "Not responding" for the delay but closes without segfault

hugleo commented 6 months ago

@hugleo may be on to something?

diff --git a/ffi-cdecl/SDL2_0_decl.c b/ffi-cdecl/SDL2_0_decl.c
index a9135664..41837803 100644
--- a/ffi-cdecl/SDL2_0_decl.c
+++ b/ffi-cdecl/SDL2_0_decl.c
@@ -129,6 +129,7 @@ cdecl_func(SDL_Delay)
 cdecl_func(SDL_GetCurrentDisplayMode)
 cdecl_func(SDL_EnableScreenSaver)
 cdecl_func(SDL_CreateWindow)
+cdecl_func(SDL_DestroyWindow)
 cdecl_func(SDL_GetWindowSize)
 cdecl_func(SDL_CreateRenderer)
 cdecl_func(SDL_DestroyRenderer)
diff --git a/ffi/SDL2_0.lua b/ffi/SDL2_0.lua
index 77573bf9..864ff658 100644
--- a/ffi/SDL2_0.lua
+++ b/ffi/SDL2_0.lua
@@ -132,10 +132,11 @@ function S.open(w, h, x, y)
     -- set up screen (window)
     local pos_x = tonumber(os.getenv("KOREADER_WINDOW_POS_X")) or x or SDL.SDL_WINDOWPOS_UNDEFINED
     local pos_y = tonumber(os.getenv("KOREADER_WINDOW_POS_Y")) or y or SDL.SDL_WINDOWPOS_UNDEFINED
-    S.screen = SDL.SDL_CreateWindow("KOReader",
+    S.screen = ffi.gc(SDL.SDL_CreateWindow("KOReader",
         pos_x, pos_y,
         S.win_w, S.win_h,
-        bit.bor(full_screen and SDL.SDL_WINDOW_FULLSCREEN or 0, SDL.SDL_WINDOW_RESIZABLE, SDL.SDL_WINDOW_ALLOW_HIGHDPI)
+        bit.bor(full_screen and SDL.SDL_WINDOW_FULLSCREEN or 0, SDL.SDL_WINDOW_RESIZABLE, SDL.SDL_WINDOW_ALLOW_HIGHDPI)),
+        SDL.SDL_DestroyWindow
     )
     -- For some mysterious reason, CreateWindow doesn't give a damn about the initial position, and will enforce top-left (we get an SDL_WINDOWEVENT_MOVED), so, force its hand...
     -- What's even more curious is that we still only get a single SDL_WINDOWEVENT_MOVED on startup, except that way it's at the requested coordinates...
diff --git a/ffi/SDL2_0_h.lua b/ffi/SDL2_0_h.lua
index aebf9774..ce69b80c 100644
--- a/ffi/SDL2_0_h.lua
+++ b/ffi/SDL2_0_h.lua
@@ -792,6 +792,7 @@ void SDL_Delay(Uint32) __attribute__((visibility("default")));
 int SDL_GetCurrentDisplayMode(int, SDL_DisplayMode *) __attribute__((visibility("default")));
 void SDL_EnableScreenSaver(void) __attribute__((visibility("default")));
 SDL_Window *SDL_CreateWindow(const char *, int, int, int, int, Uint32) __attribute__((visibility("default")));
+void SDL_DestroyWindow(SDL_Window *) __attribute__((visibility("default")));
 void SDL_GetWindowSize(SDL_Window *, int *, int *) __attribute__((visibility("default")));
 SDL_Renderer *SDL_CreateRenderer(SDL_Window *, int, Uint32) __attribute__((visibility("default")));
 void SDL_DestroyRenderer(SDL_Renderer *) __attribute__((visibility("default")));

Does seem to prevent a segfault on exit over here (X11).

(Or it just decided to stop crashing tonight ;D).

X11 was not crashing.

With these changes still crash for wayland:

SDL_VIDEODRIVER=wayland ./kodev run

01/17/24-14:47:02 DEBUG AutoSuspend: onCloseWidget 01/17/24-14:47:02 DEBUG AutoSuspend: unschedule suspend/shutdown timer 01/17/24-14:47:02 DEBUG Tearing down FileManager table: 0x7fee35830be8 01/17/24-14:47:02 DEBUG close widget: table: 0x7fee347b8b78 01/17/24-14:47:02 DEBUG refresh on logical rectangle 540x720+0+0 01/17/24-14:47:02 INFO UIManager: No dialogs left to show 01/17/24-14:47:02 INFO Tearing down UIManager with exit code: 0 warning: queue 0x5559257689a0 destroyed while proxies still attached: wl_display@1 still attached ./kodev: line 772: 187295 Segmentation fault (core dumped) env EMULATE_READER_W="${screen_width}" EMULATE_READER_H="${screen_height}" EMULATE_READER_DPI="${screen_dpi}" ${KOREADER_COMMAND} ~/Desktop/koreader/koreader

Frenzie commented 6 months ago

Does seem to prevent a segfault on exit over here (X11).

(Or it just decided to stop crashing tonight ;D).

I tested that yesterday already. It doesn't crash on X11 and it crashes on Wayland as expected.

just tested, and it goes "Not responding" for the delay but closes without segfault

Thanks.

NiLuJe commented 6 months ago

Is the backtrace any different?

Frenzie commented 6 months ago

Note for example https://github.com/libsdl-org/SDL/pull/7623

hugleo commented 6 months ago

Note for example https://github.com/libsdl-org/SDL/pull/7623

Yes, also notice this weirdness, but since I not see the line in @hasezoey log I assume that not all video cards "override" this feature. The SDL_waylandwindow.c from 2.28.5 already have this fix but I'll check later if something else is messing with the libs.

Frenzie commented 6 months ago

@NiLuJe Trace with that diff btw. I think it's identical.

``` #0 0x00007ffff696cf60 in ?? () #1 0x00007ffff7829e83 in GL_DestroyTexture (renderer=, texture=0x55555797f540) at /usr/src/libsdl2-2.28.3+dfsg-2/src/render/opengl/SDL_render_gl.c:1509 #2 0x00007ffff783000c in SDL_DestroyTexture_REAL (texture=0x55555797f540) at /usr/src/libsdl2-2.28.3+dfsg-2/src/render/SDL_render.c:4287 #3 0x00007ffff7830203 in SDL_DestroyTexture_REAL (texture=) at /usr/src/libsdl2-2.28.3+dfsg-2/src/render/SDL_render.c:4253 #4 SDL_DestroyRenderer_REAL (renderer=0x5555556f1700) at /usr/src/libsdl2-2.28.3+dfsg-2/src/render/SDL_render.c:4326 #5 SDL_DestroyRenderer_REAL (renderer=0x5555556f1700) at /usr/src/libsdl2-2.28.3+dfsg-2/src/render/SDL_render.c:4295 #6 0x000055555557b5a9 in lj_vm_ffi_call () at buildvm_x86.dasc:2707 #7 0x000055555559e4c3 in lj_ccall_func (L=L@entry=0x7ffff7f9e380, cd=) at lj_ccall.c:1187 #8 0x0000555555576dfe in lj_cf_ffi_meta___call (L=0x7ffff7f9e380) at lib_ffi.c:230 #9 0x0000555555579146 in lj_BC_FUNCC () at buildvm_x86.dasc:857 #10 0x000055555557b916 in gc_call_finalizer (g=g@entry=0x7ffff7f9e3e0, L=L@entry=0x7ffff7f9e380, mo=mo@entry=0x7fffffffd518, o=0x7ffff7a5e780) at lj_gc.c:521 #11 0x000055555557c8eb in lj_gc_finalize_cdata (L=L@entry=0x7ffff7f9e380) at lj_gc.c:602 #12 0x0000555555561573 in cpfinalize (L=0x7ffff7f9e380, dummy=, ud=) at lj_state.c:289 #13 0x000055555557953c in lj_vm_cpcall () at buildvm_x86.dasc:1246 #14 0x0000555555561972 in lua_close (L=L@entry=0x7ffff7f9e380) at lj_state.c:316 #15 0x00005555555a933c in lj_cf_os_exit (L=0x7ffff7f9e380) at lib_os.c:120 #16 0x0000555555579146 in lj_BC_FUNCC () at buildvm_x86.dasc:857 #17 0x0000555555567912 in lua_pcall (L=L@entry=0x7ffff7f9e380, nargs=nargs@entry=0, nresults=-1, errfunc=errfunc@entry=2) at lj_api.c:1150 #18 0x000055555555c99f in docall (L=L@entry=0x7ffff7f9e380, narg=narg@entry=0, clear=clear@entry=0) at luajit.c:122 #19 0x000055555555d222 in handle_script (L=L@entry=0x7ffff7f9e380, argx=argx@entry=0x7fffffffd900) --Type for more, q to quit, c to continue without paging-- at luajit.c:292 #20 0x000055555555d904 in pmain (L=0x7ffff7f9e380) at luajit.c:550 #21 0x0000555555579146 in lj_BC_FUNCC () at buildvm_x86.dasc:857 #22 0x0000555555567969 in lua_cpcall (L=L@entry=0x7ffff7f9e380, func=func@entry=0x55555555d7ab , ud=ud@entry=0x0) at lj_api.c:1178 #23 0x000055555555d9c8 in main (argc=2, argv=0x7fffffffd8f8) at luajit.c:581 ```
Frenzie commented 6 months ago

No problem like so:

-    S.renderer = ffi.gc(SDL.SDL_CreateRenderer(S.screen, -1, 0), SDL.SDL_DestroyRenderer)
+    S.renderer = SDL.SDL_CreateRenderer(S.screen, -1, 0), SDL.SDL_DestroyRenderer

(That's from https://github.com/koreader/koreader-base/pull/1667)

Frenzie commented 6 months ago

Still works okay if you do this, which I think should be equivalent in intent to using ffi.gc:

@@ -165,6 +166,9 @@ function framebuffer:setWindowIcon(icon)
 end

 function framebuffer:close()
+    SDL.SDL.SDL_DestroyRenderer(SDL.renderer)
     SDL.SDL.SDL_Quit()
 end

Now I don't really see what that'd necessary be for since SDL_Quit() is supposed to take care of that, but I'll grant it's clearer in any case.

Edit: I'm not particularly motivated to dive deeper right now, but a possible hypothesis might be SDL_Quit() cleans it up already and then ffi.gc kicks in with the finalizer and comes up empty.No, it says it just returns in that case.

NiLuJe commented 6 months ago

Might be an ordering issue (since IIRC, that's an issue with finalizers, you don't really have any guarantee of specific ordering, and the GC resurrecting a dead object might screw that up further).

In any case, we don't really have any other way of destroying the renderer (I think?), so this sounds good ;).

Frenzie commented 6 months ago

But like I said, SDL_Quit does it for you, or is supposed to. (Destroy any and all renderers is what I mean here specifically, but obviously also windows etc.) You can do it yourself for clarity so people not familiar with SDL won't wonder why you're not doing it and then SDL_Quit will have less to do.

Of course I imagine the PR in question came from Valgrind and not from code gazing, which leaves me a bit puzzled.

Thinking about it a bit more, running SDL_DestroyRenderer that way instead of with ffi.gc seems preferable regardless, both for the aforementioned clarity (but in this case because putting it there with ffi.gc puts it in an unexpected place, at least for people who don't know LuaJIT) and because you should avoid ffi.gc when reasonably possible to avoid overhead. Not that overhead matters here, but it's proably a better example to follow. ;-)

Code organization-wise maybe it should be moved into the SDL file though…?

NiLuJe commented 6 months ago

Code organization-wise maybe it should be moved into the SDL file though…?

Eh, seems fine (I'm not super fond of gratuitous indirection anyway).

But like I said, SDL_Quit does it for you, or is supposed to.

I didn't try to unwind the code too much, but at a glance, I don't actually see this happening anywhere? It destroys windows & surfaces, yeah, but renderer? Nope.

hugleo commented 6 months ago

Code organization-wise maybe it should be moved into the SDL file though…?

Eh, seems fine (I'm not super fond of gratuitous indirection anyway).

But like I said, SDL_Quit does it for you, or is supposed to.

I didn't try to unwind the code too much, but at a glance, I don't actually see this happening anywhere? It destroys windows & surfaces, yeah, but renderer? Nope.

You are right.

Set in SDL2_0.lua like

S.renderer = SDL.SDL_CreateRenderer(S.screen, -1, 0) 

and like that in framebuffer_SDL2_0.lua

function framebuffer:close()
    SDL.SDL.SDL_Quit()
    SDL.SDL.SDL_DestroyRenderer(SDL.renderer)
end

will cause the same error and is not using ffi.gc

Frenzie commented 6 months ago

Huh, in that case I must be confused with for example:

/**
 * Use this function to shut down audio if you initialized it with
 * SDL_AudioInit().
 *
 * This function is used internally, and should not be used unless you have a
 * specific need to specify the audio driver you want to use. You should
 * normally use SDL_Quit() or SDL_QuitSubSystem().

Indeed it doesn't say you should or can call SDL_Quit instead of SDL_DestroyRenderer, but I'm reasonably sure I read that in an SDL tutorial years ago and stored it in my mind as SDL knowledge. D:

extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);

/**
 * Destroy the rendering context for a window and free associated textures.
 *
 * If `renderer` is NULL, this function will return immediately after setting
 * the SDL error message to "Invalid renderer". See SDL_GetError().
 *
 * \param renderer the rendering context
 *
 * \since This function is available since SDL 2.0.0.
 *
 * \sa SDL_CreateRenderer
 */
extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
hugleo commented 6 months ago

Here is using it:

https://github.com/libsdl-org/SDL/blob/main/docs/README-visualc.md?plain=1#L93

https://github.com/libsdl-org/SDL/blob/main/src/test/SDL_test_common.c#L2538C1-L2538C52

Frenzie commented 6 months ago

https://github.com/libsdl-org/SDL/blob/main/src/test/SDL_test_common.c#L2538C1-L2538C52

That one's definitely destroying things SDL_Quit (should) also do automatically though, give or take the renderer. :-)

Anyway, I'll toss it in a PR.