Bug 233438

Summary: Digikam crash when editing raw images on OS X
Product: [Applications] digikam Reporter: brad <bkn>
Component: Plugin-DImg-RAWAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: caulier.gilles, lexa
Priority: NOR    
Version: 1.2.0   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Other   
Latest Commit: Version Fixed In: 1.6.0
Sentry Crash Report:
Attachments: posible fix for crash in OS X.

Description brad 2010-04-06 01:12:40 UTC
Version:           1.2.0 (using KDE 4.4.2)
OS:                OS X
Installed from:    Compiled From Sources

KDE{libs,graphics} 
  Version: 4.4.2
  Dist: Compiled form sources from macports

Digikam and Kipi 
  Version 1.2.0
  Dist: Compiles form svn

To Reproduce:
  Select any RAW image (for me it's a RAW from Canon XSI, or chdk) and select Edit image. After a few moments (less than a minute), digikam will crash. Below is the backtrace. Note: digikam does not crash if you try edit a JPEG. I compiled digikam with -DCMAKE_BUILD_TYPE=debugfull so i was expecting more debug information. I figure that most developers do not have access to a Mac, please let me know if there are code changes you want me to try locally to try to fix the problem. Also if you need any more information, please let me know and i will furnish it. 


-- BEGIN BACKTRACE --:
digikam(26352)/digikam (core) Digikam::DImg::load: "/Volumes/Home Directory/Pictures/2008-12-17-BearMountain/img_2426.cr2"  : RAW file identified
Wavelet denoising...

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000010
[Switching to process 26352]
0x000000010138402c in gomp_resolve_num_threads ()
(gdb) bt
#0  0x000000010138402c in gomp_resolve_num_threads ()
#1  0x00000001013840ad in GOMP_parallel_start ()
#2  0x00000001013607b7 in LibRaw::wavelet_denoise ()
#3  0x0000000101370750 in LibRaw::scale_colors ()
#4  0x0000000101380bff in LibRaw::dcraw_process ()
#5  0x0000000101343430 in KDcrawIface::KDcraw::loadFromLibraw ()
#6  0x000000010134595e in KDcrawIface::KDcraw::decodeRAWImage ()
#7  0x0000000101857e55 in Digikam::RAWLoader::load (this=0x11d7784d0, filePath=@0x1202c9bc8, observer=0x1202c9bc0) at /Users/brad/source/kde4/graphics/digikam/libs/dimg/loaders/rawloader.cpp:101
#8  0x0000000101838c50 in Digikam::DImg::load (this=0x11d778e50, filePath=@0x1202c9bc8, loadFlagsInt=31, observer=0x1202c9bc0, rawDecodingSettings=@0x11d778b60) at /Users/brad/source/kde4/graphics/digikam/libs/dimg/dimg.cpp:439
#9  0x0000000101839862 in Digikam::DImg::load (this=0x11d778e50, filePath=@0x1202c9bc8, observer=0x1202c9bc0, rawDecodingSettings=@0x11d778c80) at /Users/brad/source/kde4/graphics/digikam/libs/dimg/dimg.cpp:340
#10 0x000000010183ab27 in Digikam::DImg::DImg (this=0x11d778e50, filePath=@0x1202c9bc8, observer=0x1202c9bc0, rawDecodingSettings=@0x11d778d80) at /Users/brad/source/kde4/graphics/digikam/libs/dimg/dimg.cpp:99
#11 0x00000001019bb746 in Digikam::LoadingTask::execute (this=0x1202c9bb0) at /Users/brad/source/kde4/graphics/digikam/libs/threadimageio/loadsavetask.cpp:48
#12 0x00000001019ab945 in Digikam::LoadSaveThread::run (this=0x120262280) at /Users/brad/source/kde4/graphics/digikam/libs/threadimageio/loadsavethread.cpp:134
#13 0x0000000104058da5 in QThreadPrivate::start ()
#14 0x00007fff81b668b6 in _pthread_start ()
#15 0x00007fff81b66769 in thread_start ()
Comment 1 caulier.gilles 2010-04-06 08:27:50 UTC
Which libkdcraw and libraw you use. Please go to Help/Components info dialog for details.

Gilles Caulier
Comment 2 caulier.gilles 2010-04-06 08:29:05 UTC
The crash appears in libgomp (GCC extension). Which gcc version you use ?

Gilles Caulier
Comment 3 brad 2010-04-06 13:49:58 UTC
gcc --version

i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646) (dot 1)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



Components Versions:

digiKam version 1.2.0 (rev.: 1108543)
Exiv2 can write to Jp2: Yes
Exiv2 can write to Jpeg: Yes
Exiv2 can write to Pgf: No
Exiv2 can write to Png: Yes
Exiv2 can write to Tiff: Yes
Exiv2 supports XMP metadata: Yes
LibCImg: 130
LibExiv2: 0.18.2
LibJPEG: 80
LibJasper: 1.900.1
LibKDE: 4.4.2 (KDE 4.4.2)
LibKExiv2: 1.0.0
LibKdcraw: 1.0.0
LibLCMS: 119
LibPGF: 6.09.44
LibPNG: 1.2.43
LibQt: 4.6.2
LibRaw: 0.8.5
LibTIFF: LIBTIFF, Version 3.9.2 Copyright (c) 1988-1996 Sam Leffler Copyright (c) 1991-1996 Silicon Graphics, Inc.
Parallelized demosaicing: Yes
LibGphoto2: 2.4.5
LibKipi: 1.0.0
Comment 4 brad 2010-10-16 20:54:45 UTC
An update on this bug. I just sent this message to the kdegraphics-devel list and the libraw mailing list. It turns out the bug is in dcraw_common.cpp where the OpenMP version of wavelet_denoise() is used on OS X, but the OpenMP version crashes under OS X (see above). The normal version of the wavelet_denoise executes just fine under OS X. Below is the message to the mailing lists.

-----

I've been fighting a crash w/ digikam for months. I reported the bug here if > you want more info:
https://bugs.kde.org/show_bug.cgi?id=233438

The bug is in libraw/internal/dcraw_common.cpp. It appears there are two versions of the wavelet_denoise() function, one uses OpenMP for parallel processing, the other is just a normal linear executing function. When this file is compiled under OS X it compiles the OpenMP version of the function, which crashes on OS X. The simple fix is to use the linear version of wavelet_denoise() on OS X. Below is an ad-hoc patch:

dcraw_common.cpp: 3186

+/* the OpenMP parallel version of this function appears to be crashing under OS
+ * X; therefor just use the non OpenMP version of this funciton on OS X
+ */
+#if !defined(_OPENMP) || defined(__APPLE__) || defined(__MACOSX__)
-#ifndef(_OPENMP)
void CLASS wavelet_denoise()$
{


I am not familiar with OpenMP nor do i understand how dcraw_common.cpp is generated so it is difficult for me to debug. If someone is willing to give me info how these things work i can try to get the OpenMP version work on OS X.
Comment 5 Alex Tutubalin 2010-10-16 21:14:05 UTC
I cannot reproduce the problem with latest LibRaw (0.11-Beta6) and gcc 4.2.1 apple build 5664 (the build number is dfferent from yours, I use latest xcode).
I use dcraw_emu sample from LibRaw.

There is a difference in OpenMP directives in yours 0.8.5 and more fresh ones. 

Could you please try digiKam 1.5.0 (with last stable LibRaw 0.10) ?
Comment 6 Alex Tutubalin 2010-10-16 21:22:50 UTC
  Brad,

I've found your compiler version details in KDE bugs site (see my reply 
in bug tracker)

There are two significant differences:

  1) There was a change in OpenMP directives in wavelet denoise in 
0.10-Beta1. So, 0.10.0 (stable release) may behave differently with 
0.8.5 you use
  2) Compiler version is slightly differ.

Anyway, I cannot reproduce the problem for now.

I thing, it is better to continue discussion in KDE bugs interface, not 
in private mail.

On 10/16/2010 10:54 PM, brad wrote:
> https://bugs.kde.org/show_bug.cgi?id=233438
>
>
>
>
>
> --- Comment #4 from brad<bkn ithryn net>   2010-10-16 20:54:45 ---
> An update on this bug. I just sent this message to the kdegraphics-devel list
> and the libraw mailing list. It turns out the bug is in dcraw_common.cpp where
> the OpenMP version of wavelet_denoise() is used on OS X, but the OpenMP version
> crashes under OS X (see above). The normal version of the wavelet_denoise
> executes just fine under OS X. Below is the message to the mailing lists.
>
> -----
>
> I've been fighting a crash w/ digikam for months. I reported the bug here if>
> you want more info:
> https://bugs.kde.org/show_bug.cgi?id=233438
>
> The bug is in libraw/internal/dcraw_common.cpp. It appears there are two
> versions of the wavelet_denoise() function, one uses OpenMP for parallel
> processing, the other is just a normal linear executing function. When this
> file is compiled under OS X it compiles the OpenMP version of the function,
> which crashes on OS X. The simple fix is to use the linear version of
> wavelet_denoise() on OS X. Below is an ad-hoc patch:
>
> dcraw_common.cpp: 3186
>
> +/* the OpenMP parallel version of this function appears to be crashing under
> OS
> + * X; therefor just use the non OpenMP version of this funciton on OS X
> + */
> +#if !defined(_OPENMP) || defined(__APPLE__) || defined(__MACOSX__)
> -#ifndef(_OPENMP)
> void CLASS wavelet_denoise()$
> {
>
>
> I am not familiar with OpenMP nor do i understand how dcraw_common.cpp is
> generated so it is difficult for me to debug. If someone is willing to give me
> info how these things work i can try to get the OpenMP version work on OS X.
>
Comment 7 brad 2010-10-16 21:36:07 UTC
Created attachment 52575 [details]
posible fix for crash in OS X.
Comment 8 brad 2010-10-16 21:36:30 UTC
The above versioning information is a bit dated as i first ran into this bug
several months ago. The new version information is below.

Xcode:
Xcode 3.2.4
Component versions: DevToolsCore-1705.0; DevToolsSupport-1591.0
BuildVersion: 10M2309

GCC Version:
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


DIGIKAM Version:

digiKam version 1.5.0 (rev.: 1185190)
Exiv2 can write to Jp2: Yes
Exiv2 can write to Jpeg: Yes
Exiv2 can write to Pgf: No
Exiv2 can write to Png: Yes
Exiv2 can write to Tiff: Yes
Exiv2 supports XMP metadata: Yes
LibCImg: 130
LibExiv2: 0.19
LibJPEG: 80
LibJasper: 1.900.1
LibKDE: 4.5.2 (KDE 4.5.2)
LibKExiv2: 1.1.0
LibKdcraw: 1.1.0
LibLCMS: 119
LibPGF: 6.09.44
LibPNG: 1.2.44
LibQt: 4.7.0
LibRaw: 0.10.0
LibTIFF: LIBTIFF, Version 3.9.4 Copyright (c) 1988-1996 Sam Leffler Copyright
(c) 1991-1996 Silicon Graphics, Inc.
Parallelized demosaicing: Yes
Database backend: QSQLITE
LibGphoto2: 2.4.9.1
LibKipi: 1.1.0

My patch above contained extra parens be mistake as I am not good at making
patches. I attached a more proper patch.

I have digikam-1.5.0 compiled from source and i have kdegraphics-4.5.2 compiled
form MacPorts (with homebrew Portfile as macports is a little behind on the kde
releases). 

How do you have libraw 0.11 compiled and installed? do you just install it over
the kdegraphics version or do you not have kdegraphics installed at all? I'd
like to try to duplicate your environment. Perhaps i've been building things
incorrectly.
Comment 9 Alex Tutubalin 2010-10-18 11:54:21 UTC
The patch is applied to LibRaw 0.11-Beta7 (http://www.libraw.org/data/LibRaw-0.11.0-Beta7.tar.gz)

Because I cannot reproduce the problem on my MacOS (and with LibRaw own samples), I cannot test the patch really helps or not.
Comment 10 caulier.gilles 2010-10-18 12:28:13 UTC
SVN commit 1187116 by cgilles:

update internal libraw to 0.11.0-beta7
BUGS: 233438


 M  +5 -1      Changelog.txt  
 A             README  
 M  +1 -1      internal/dcraw_common.cpp  
 M  +6 -5      libraw/libraw_datastream.h  
 M  +1 -1      libraw/libraw_version.h  
 M  +1 -1      samples/dcraw_emu.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1187116
Comment 11 caulier.gilles 2010-10-18 12:34:26 UTC
Alex,

libraw updated in KDE 4.6 (trunk) and KDE4.5 branch.

Q: do you plan to update libraw to support liblcms version 2.x where API have been re-written indeep ?

http://www.littlecms.com/

Gilles Caulier
Comment 12 Alex Tutubalin 2010-10-18 13:17:30 UTC
Gilles,

according to Marti Maria, old programs should compile fine with LCMS2. Have not tried yet, will try.

P.S. I guess, it would be better to create another bug or move to private mail with LCMS-related issues.