Bug 494754

Summary: Customized Raw Import Tool Crashes (Randomly) When Using Image Editor
Product: [Applications] digikam Reporter: qp.ding
Component: Setup-ImageEditorAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: crash CC: caulier.gilles, metzpinguin, qp.ding
Priority: NOR    
Version: 8.5.0   
Target Milestone: ---   
Platform: macOS (DMG)   
OS: macOS   
Latest Commit: Version Fixed In: 8.5.0
Sentry Crash Report:
Attachments: OS prompt when the edit in darktable fails

Description qp.ding 2024-10-14 17:08:33 UTC
Created attachment 174814 [details]
OS prompt when the edit in darktable fails

SUMMARY
The customized raw import tool (darktable or rawtherapee) will crash when using image editor.

STEPS TO REPRODUCE
1. Set to "Raw Import Using DarkTable" in Configure -> Image Editor -> Raw Behavior
2. Select a raw image, then click Image Editor
3. The image editor will pop up, and a darktable instance will run successfully.

OBSERVED RESULT
When trying to edit the file in darktable, MacOS will give a warning saying that darktable has crashed.
But it's weird that it happens in like 8 out of 10 trials. I did manage to successfully conduct editing and get the exported file back to digikam once.

EXPECTED RESULT
The image file can be edited and exported normally.

SOFTWARE/OS VERSIONS
digikam 8.5.0 pre-release (Build Date: 14/10/2024 08:07)
macOS: 15.0.1 (Apple Silicon)

ADDITIONAL INFORMATION
When the edit fails leading to darktable crashing, the internal logging shows:
-----------------------------------
digikam.geoiface: ----
digikam.dplugin.rawimport: DarkTable arguments: QList("--library", ":memory:", "--luacmd", "dofile('/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.LrSKkp')", "--conf", "plugins/lighttable/export/icctype=3", "--conf", "lua/export_on_exit/export_filename=/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.cUQvzw", "/System/Volumes/Data/Users/quinn/Pictures/digikam_garage/20240918T172644_3665.ARW")
qt.accessibility.table: Cell requested for row 0 is out of bounds for table with 0 rows! Resizing table model.
QProcess::readAllStandardError: Called with MergedChannels
qt.pointer.dispatch: skipping QEventPoint(id=1 ts=0 pos=0,0 scn=213.375,264.864 gbl=213.375,264.864 Released ellipse=(1x1 ∡ 0) vel=0,0 press=-213.375,-264.864 last=-213.375,-264.864 Δ 213.375,264.864) : no target window
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
digikam.dplugin.rawimport: DarkTable :: Process has crashed
digikam.dplugin.rawimport: DarkTable :: return code: 11 :: Exit status: QProcess::CrashExit
digikam.dimg: File "/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.cUQvzw" does not exist
digikam.dplugin.rawimport: Decoded image is null! Load with Native tool...
digikam.dplugin.rawimport: "/System/Volumes/Data/Users/quinn/Pictures/digikam_garage/20240918T172644_3665.ARW"
-----------------------------------
I checked in /private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/ and the file digikam.cUQvzw really does not exist. I guess it's a generated temporary file, but it looks clear that its absence caused the crash because the export_filename depends on it.

When I got lucky and made a successful edit and export, the internal logging is:
-----------------------------------
digikam.geoiface: ----
digikam.dplugin.rawimport: DarkTable arguments: QList("--library", ":memory:", "--luacmd", "dofile('/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.LrSKkp')", "--conf", "plugins/lighttable/export/icctype=3", "--conf", "lua/export_on_exit/export_filename=/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.AfEQdh", "/System/Volumes/Data/Users/quinn/Pictures/digikam_garage/20240918T172644_3665.ARW")
qt.accessibility.table: Cell requested for row 0 is out of bounds for table with 0 rows! Resizing table model.
QProcess::readAllStandardError: Called with MergedChannels
qt.pointer.dispatch: skipping QEventPoint(id=1 ts=0 pos=0,0 scn=16.1349,104.283 gbl=16.1349,104.283 Released ellipse=(1x1 ∡ 0) vel=0,0 press=-16.1349,-104.283 last=-16.1349,-104.283 Δ 16.1349,104.283) : no target window
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
QProcess::readAllStandardError: Called with MergedChannels
digikam.dplugin.rawimport: DarkTable :: return code: 0 :: Exit status: QProcess::NormalExit
digikam.dimg: "/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.AfEQdh" : "PNG" file identified (magic)
digikam.metaengine: Loading metadata with "Exiv2" backend from "/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.AfEQdh"
digikam.dimg.png: Opening file "/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.AfEQdh"
digikam.dimg.png: PNG in >=8 bits/color/pixel.
digikam.dimg.png: PNG in PNG_COLOR_TYPE_RGB
digikam.dplugin.rawimport: Decoded image is not null...
digikam.dplugin.rawimport: "/System/Volumes/Data/Users/quinn/Pictures/digikam_garage/20240918T172644_3665.ARW"
digikam.database: No location could be retrieved for "/private/var/folders/fm/scct14x5025d_05z2nyx9v800000gn/T/digikam.AfEQdh"
qt.pointer.dispatch: skipping QEventPoint(id=1 ts=0 pos=0,0 scn=638.375,125.185 gbl=638.375,125.185 Released ellipse=(1x1 ∡ 0) vel=0,0 press=-638.375,-125.185 last=-638.375,-125.185 Δ 638.375,125.185) : no target window
-----------------------------------

Switching to RawTherapee is just as similar with an OS prompt, only that the RawTherapee instance will not run at all.
Comment 1 Maik Qualmann 2024-10-14 17:37:07 UTC
Hmm, the temporary file should actually be created by Darktable, we pass it on as a placeholder. But it's possible that we just delete it from under Darktable's feet. I'll change something.

Maik
Comment 2 Maik Qualmann 2024-10-14 18:17:50 UTC
Git commit 0e2854fc36dbdae3cacd1e935642c5eea7fbd274 by Maik Qualmann.
Committed on 14/10/2024 at 18:16.
Pushed by mqualmann into branch 'master'.

use SafeTemporaryFile for the Darktable editor plugin

M  +26   -16   core/dplugins/rawimport/darktable/rawimportdarktableplugin.cpp

https://invent.kde.org/graphics/digikam/-/commit/0e2854fc36dbdae3cacd1e935642c5eea7fbd274
Comment 3 Maik Qualmann 2024-10-14 18:37:54 UTC
Git commit 6213e0394ce56917853a8f74f9ec9e6973d15cc4 by Maik Qualmann.
Committed on 14/10/2024 at 18:36.
Pushed by mqualmann into branch 'master'.

use SafeTemporaryFile for the RawTherapee and ART editor plugin

M  +14   -10   core/dplugins/rawimport/art/rawimportartplugin.cpp
M  +2    -2    core/dplugins/rawimport/darktable/rawimportdarktableplugin.cpp
M  +14   -10   core/dplugins/rawimport/rawtherapee/rawimportrawtherapeeplugin.cpp

https://invent.kde.org/graphics/digikam/-/commit/6213e0394ce56917853a8f74f9ec9e6973d15cc4
Comment 4 Maik Qualmann 2024-10-14 19:06:52 UTC
But the whole thing could also be a Darktable problem. I tested it here, whether the temporary file exists or not (it is the target file for the image) doesn't matter. It is created by Darktable under the given name.

In any case, it is no longer deleted after starting Darktable. We will see if there is a change with the next macOS bundle.

Maik
Comment 5 qp.ding 2024-10-15 12:22:50 UTC
(In reply to Maik Qualmann from comment #4)
> But the whole thing could also be a Darktable problem. I tested it here,
> whether the temporary file exists or not (it is the target file for the
> image) doesn't matter. It is created by Darktable under the given name.
> 
> In any case, it is no longer deleted after starting Darktable. We will see
> if there is a change with the next macOS bundle.
> 
> Maik

I can also confirm that it should be a darktable problem upon some extensive testing. Already filed a new issue on the darktable side and hopefully can get some useful information.
https://github.com/darktable-org/darktable/issues/17671
Comment 6 qp.ding 2024-10-16 09:09:22 UTC
Played around with digikam 8.5.0 and darktable of older versions (4.8.0 and 4.6.1), the problem is no longer reproducible. It happens with the latest darktable 4.8.1.

Not sure if you need to revert the two commits mentioned above, but just want to update the results.
Comment 7 Maik Qualmann 2024-10-16 17:17:13 UTC
No, we do not have to reverse the changes here, they are definitely better.
Thanks for the feedback.

Maik