Bug 201302 - Crash due to memory access problem on Mac OS X
Summary: Crash due to memory access problem on Mac OS X
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Portability-Runtime (show other bugs)
Version: 1.0.0
Platform: Fink Packages macOS
: NOR crash
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-24 01:34 UTC by rishi.j.sanyal
Modified: 2022-01-31 12:34 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 1.0.0


Attachments
endianess destection using Qt4 flags (747 bytes, patch)
2009-07-29 09:37 UTC, caulier.gilles
Details

Note You need to log in before you can comment on or make changes to this bug.
Description rishi.j.sanyal 2009-07-24 01:34:34 UTC
Version:           1.0.0-beta2 (using KDE 4.2.0)
Compiler:          gcc 4.0.1 
OS:                OS X
Installed from:    Mac OS X (Fink) Packages

After Gilles worked out all the kinks with compiling on Mac OS X, I can successfully compile most, if not all, recent SVN versions of digiKam. However, unless one has installed version 4.2.0 (not 4.2.4) of all KDE components using MacPorts, digiKam & dngconverter will never launch due to something wrong with "kdelibs. Your core libs are corrupted." (I'm quoting Gilles there!).

Luckily, I went back to a backup of my OS that had an older Darwin Ports installation. This allowed me to install version 4.2.0 of all KDE stuff on OS X.

Now, dngconverter works fine. digiKam works fine for a little bit, until it crashes while trying to load some thumbnails or an image. Here is the relevant backtrace:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x16290000
[Switching to process 35637 thread 0x5a1b]
0x01513420 in CDecoder::DecodeBuffer (this=0x1626f000) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/3rdparty/libpgf/Decoder.cpp:446
446			m_codeBuffer[i] = __VAL(m_codeBuffer[i]);
(gdb) bt
#0  0x01513420 in CDecoder::DecodeBuffer (this=0x1626f000) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/3rdparty/libpgf/Decoder.cpp:446
#1  0x015134ee in CDecoder::DequantizeValue (this=0x1626f000, band=0x15ba6654, bandPos=0, quantParam=0) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/3rdparty/libpgf/Decoder.cpp:395
#2  0x01513b3d in CDecoder::Partition (this=0x1626f000, band=0x15ba6654, quantParam=0, width=64, height=47, startPos=0, pitch=64) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/3rdparty/libpgf/Decoder.cpp:212
#3  0x0151eec0 in CSubband::PlaceTile (this=0x15ba6654, decoder=@0x1626f000, quantParam=0, tile=false, tileX=0, tileY=0) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/3rdparty/libpgf/Subband.cpp:226
#4  0x01517064 in CPGFImage::Read (this=0xb02c2638, level=0, cb=0, data=0x0) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/3rdparty/libpgf/PGFimage.cpp:286
#5  0x01520fa2 in Digikam::readPGFImageData (data=@0xb02c2bf4, img=@0xb02c2bd4) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/threadimageio/pgfutils.cpp:68
#6  0x014f9370 in Digikam::ThumbnailCreator::loadFromDatabase (this=0x1523c900, info=@0xb02c2cd8) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/threadimageio/thumbnailcreator.cpp:573
#7  0x014fbac1 in Digikam::ThumbnailCreator::load (this=0x1523c900, path=@0x15ba837c) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/threadimageio/thumbnailcreator.cpp:182
#8  0x01501953 in Digikam::ThumbnailLoadingTask::execute (this=0x15ba8370) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/threadimageio/thumbnailtask.cpp:135
#9  0x014e76f4 in Digikam::LoadSaveThread::run (this=0x1523be20) at /Users/Rishi/compile/digikam-1.0.0-beta2/libs/threadimageio/loadsavethread.cpp:139
#10 0x03639d0b in QThreadPrivate::start ()
#11 0x910b5155 in _pthread_start ()
#12 0x910b5012 in thread_start ()
Current language:  auto; currently c++
(gdb) 

If you're having trouble reading the error messages above, take a look at this .txt file of the error messages here:

http://staff.washington.edu/rjsanyal/Photography/digiKam/digiKam_1.0.0-beta2_ErrorOnMacOSX.txt

Any ideas?

Many thanks in advance,
Rishi
Comment 1 caulier.gilles 2009-07-24 06:01:15 UTC
Yes, it's in libpgf.

Run digiKam into valgrind and post trace here.

Look into HACKING file for details about memory leak and valgrind.

Gilles Caulier
Comment 2 rishi.j.sanyal 2009-07-25 02:59:01 UTC
Thanks Gilles.

Here's a link to the Valgrind output (it's really long):
http://staff.washington.edu/rjsanyal/Photography/digiKam/digiKam_ValgrindOutput.txt

But before you get too far, I just realized that when I ran 'sudo port -d selfupdate', MacPorts updated all my KDE installations from 4.2.0 to 4.2.4. Automatically. Maybe that's where the trouble is. 

So tonight I'll reinstall my OS backup and retry installing 4.2.0 versions of everything & see if the problem lies there.

Let me know if you can make any sense of the valgrind output and if it helps.

Cheers,
Rishi
Comment 3 caulier.gilles 2009-07-28 06:20:54 UTC
From Rishi by private mail :

I reinstalled my OS so I could get 4.2.0 versions of all KDE stuff,
compiled the newest SVN version of digiKam, and then used Valgrind to
trace the memory leak. See the .txt file linked below for Valgrind
output:

http://staff.washington.edu/rjsanyal/Photography/digiKam/digiKam_ValgrindOutput-2.txt

Basically, Valgrind says "The 'impossible' happened"...

GDB backtrace gives the same stuff I posted above in the first post...
i.e. something wrong with libpgf.

Trying to compile older versions of digiKam now to see if the problem goes away.

Does this help?

Many thanks,
Rishi
Comment 4 caulier.gilles 2009-07-28 06:21:39 UTC
Rishi, 

Please try digiKam 1.0.0-beta3...

Gilles
Comment 5 rishi.j.sanyal 2009-07-28 11:14:30 UTC
Gilles,

I tried the most recent SVN version of digiKam... would 1.0.0-beta3 be any different?

Thanks,
Rishi
Comment 6 caulier.gilles 2009-07-28 11:21:04 UTC
From libpgf, i think no. But a lots of digiKam part have been patched. It's always clean to use current svn especially in beta stage, because a lots of bugs are fixed...

Gilles
Comment 7 rishi.j.sanyal 2009-07-28 11:28:28 UTC
Well, I can confirm that revision 983830 of digiKam (around the June 19, 2009 SVN commit of digiKam) compiles and runs beautifully on my Mac OS X with all 4.2.0 KDE components. 

No memory leaks.

I was able to check out and compile revision 983830... it all broke somewhere after that... I'm not sure exactly at which revision it broke... I guess I could keep trying a bunch of revision between 983830 and the current version... but that would require a lot of trial & error :)

Again, as soon as I update my ports such that KDE components become 4.2.4, everything becomes broken.

Oh, I forgot, even though I hacked LensFun to compile on Mac, and even though the cmake command gives me output that says 'liblensfun library found... YES'... I can't seem to find anything LensFun related in the contextual menus when running digiKam :(

Cheers,
Rishi
Comment 8 rishi.j.sanyal 2009-07-28 11:30:50 UTC
I'm sorry, I guess what I was asking was: isn't the most recent SVN version of digiKam basically the same as 1.0.0-beta3?

P.S. Even tho LensFun isn't showing up, liquid rescale works beautifully! Cool!
Comment 9 caulier.gilles 2009-07-28 11:38:50 UTC
Revision #983830 has nothing special with libpgf :

http://websvn.kde.org/?view=rev&revision=983830

Also, excepted this commit in libpgf :

http://websvn.kde.org/?view=rev&revision=990017

all other are post #983830 :

http://websvn.kde.org/trunk/extragear/graphics/digikam/libs/3rdparty/libpgf/

So i cannot where is the problem in libpgf...

Gilles Caulier
Comment 10 caulier.gilles 2009-07-28 11:42:15 UTC
Looking your last valgrind backtrace, a lots of memory leak can be seen in marblewidget. I recommend to uninstall libmarblewidget and recompile digiKAm without it (there is no yet an option to disable marble support with cmake script...

Gilles Caulier
Comment 11 caulier.gilles 2009-07-28 22:27:59 UTC
Rishi,

Take a look below of private mail from Christoph (libpgf team):

-------------------------------------------------------------------------------

Hi Gilles

In platform.h is the symbol __BIGENDIAN__ defined for Mac OS. On Intel Macs this symbol must not be defined. Recently I got some messages that with this minor change it runs well on Intel Macs.

If the system runs on an older PowerPC Mac then I first have to organize such a machine and to do some tests, but at the moment I'm on holiday.

Christoph

-------------------------------------------------------------------------------
Comment 12 rishi.j.sanyal 2009-07-29 01:11:18 UTC
Gilles,

I did what you suggested, uninstalled libmarblewidget, made sure that digiKam compiled without it, then recompiled and ran the software. Unfortunately, it crashes right away. Here's the relevant backtrace, again pointing to libpgf:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x13b6b000
[Switching to process 88240 thread 0x5a07]
0x0155bfe0 in CDecoder::DecodeBuffer (this=0x13b4a000) at /Users/Rishi/compile/digikam/graphics/digikam/libs/3rdparty/libpgf/Decoder.cpp:446
446			m_codeBuffer[i] = __VAL(m_codeBuffer[i]);
(gdb) bt
#0  0x0155bfe0 in CDecoder::DecodeBuffer (this=0x13b4a000) at /Users/Rishi/compile/digikam/graphics/digikam/libs/3rdparty/libpgf/Decoder.cpp:446
#1  0x0155c0ae in CDecoder::DequantizeValue (this=0x13b4a000, band=0x1baddb04, bandPos=0, quantParam=0) at /Users/Rishi/compile/digikam/graphics/digikam/libs/3rdparty/libpgf/Decoder.cpp:395
#2  0x0155c6fd in CDecoder::Partition (this=0x13b4a000, band=0x1baddb04, quantParam=0, width=64, height=43, startPos=0, pitch=64) at /Users/Rishi/compile/digikam/graphics/digikam/libs/3rdparty/libpgf/Decoder.cpp:212
#3  0x01567a80 in CSubband::PlaceTile (this=0x1baddb04, decoder=@0x13b4a000, quantParam=0, tile=false, tileX=0, tileY=0) at /Users/Rishi/compile/digikam/graphics/digikam/libs/3rdparty/libpgf/Subband.cpp:226
#4  0x0155fc24 in CPGFImage::Read (this=0xb0240638, level=0, cb=0, data=0x0) at /Users/Rishi/compile/digikam/graphics/digikam/libs/3rdparty/libpgf/PGFimage.cpp:286
#5  0x01569b62 in Digikam::readPGFImageData (data=@0xb0240bf4, img=@0xb0240bd4) at /Users/Rishi/compile/digikam/graphics/digikam/libs/threadimageio/pgfutils.cpp:68
#6  0x01541fd4 in Digikam::ThumbnailCreator::loadFromDatabase (this=0x14e3cda0, info=@0xb0240cd8) at /Users/Rishi/compile/digikam/graphics/digikam/libs/threadimageio/thumbnailcreator.cpp:573
#7  0x01544711 in Digikam::ThumbnailCreator::load (this=0x14e3cda0, path=@0x1bac1aec) at /Users/Rishi/compile/digikam/graphics/digikam/libs/threadimageio/thumbnailcreator.cpp:182
#8  0x0154a513 in Digikam::ThumbnailLoadingTask::execute (this=0x1bac1ae0) at /Users/Rishi/compile/digikam/graphics/digikam/libs/threadimageio/thumbnailtask.cpp:135
#9  0x01530404 in Digikam::LoadSaveThread::run (this=0x14e3c960) at /Users/Rishi/compile/digikam/graphics/digikam/libs/threadimageio/loadsavethread.cpp:139
#10 0x03377d0b in QThreadPrivate::start ()
#11 0x92226155 in _pthread_start ()
#12 0x92226012 in thread_start ()
Current language:  auto; currently c++
(gdb) 

I can do valgrind if you want me to... Let me know.

Thanks,
Rishi
Comment 13 rishi.j.sanyal 2009-07-29 02:11:49 UTC
Gilles,

Great! I tried Christoph's suggestion, re-enabled libmarblewidget, and recompiled the most recent SVN version (beta4) of digiKam.

It works! No crash as of yet. 

So... it looks like problem solved... for now :)

Thanks very much for being so prompt & resourceful!
Cheers,
Rishi
Comment 14 rishi.j.sanyal 2009-07-29 02:13:19 UTC
Although-- I'm still confused as to why LensFun isn't showing up... in fact, no Lens Corrections are showing up in any of the contextual menus...

Did you move them/disable them?

Thanks,
Rishi
Comment 15 caulier.gilles 2009-07-29 06:16:43 UTC
>Although-- I'm still confused as to why LensFun isn't showing up... in fact, no
>Lens Corrections are showing up in any of the contextual menus...

>Did you move them/disable them?

No. it's on Enhance/Lens/Auto-Correction entry from editor menu.

Gilles Caulier
Comment 16 rishi.j.sanyal 2009-07-29 06:29:05 UTC
Interesting... It used to be in the Enhance menu on my Mac, but now these are the only items available in under the 'Enhance' menu:

Sharpen
Blur
Red Eye
Hot Pixels
In-painting
Noise Reduction
Restoration

Both the beta4 and the revision 983830 only show these items in then Enhance menu... any idea what is going on?

Thanks,
Rishi
Comment 17 caulier.gilles 2009-07-29 06:35:29 UTC
Look if files in this folder are compiled :

http://websvn.kde.org/trunk/extragear/graphics/digikam/imageplugins/lenscorrection/autocorrection/

The root folder named lenscorrection is the plugin. it include 3 tools in one. Looking your menu, this one is not installed on your system, or is not loaded at startup

run digiKam from the console and post the trace here.

Gilles
Comment 18 caulier.gilles 2009-07-29 09:37:13 UTC
Created attachment 35711 [details]
endianess destection using Qt4 flags

Rishi,

For libpgf endianess problem, i have a patch which use Qt4 flags. This cannot be used in standard libpgf code, but at least it must fix the problem at this moment.

Please, test and report...

Gilles Caulier
Comment 19 rishi.j.sanyal 2009-07-29 09:47:14 UTC
I'm sorry-- do I test by just checking out the latest SVN version of digiKam? Or do I have to apply a diff patch?

Thanks,
Rishi
Comment 20 caulier.gilles 2009-07-29 09:53:33 UTC
Revert last changes in libpgf dir using "svn revert *", and apply patch as well...

Gilles Caulier
Comment 21 rishi.j.sanyal 2009-07-29 09:58:08 UTC
Which file is the patch applied to?

Also, just so you know, all I did was delete the 'define __bigendianess' line in PGFplatform.h

That fixed the problem... can you not just take out that line?

Cheers,
Rishi
Comment 22 caulier.gilles 2009-07-29 10:10:22 UTC
Patch is attached to this file :

https://bugs.kde.org/attachment.cgi?id=35711

We need to test endianness to see if mac is intel or powerpc based to still compatible. Removing only the endianess declaration is not enough

Gilles
Comment 23 rishi.j.sanyal 2009-07-30 02:31:53 UTC
Gilles,

I applied your patch within the libpgf folder; PGFplatform.h was patched. I then recompiled digiKam... it runs just fine, so I assume your patch worked :)

As for the lenscorrection stuff-- I'm not sure what's going on. Yes I have that directory you mentioned... within the /graphics/build/digikam/imageplugins/lenscorrection directory, I have the following files:

CMakeFiles
CTestTestfile.cmake
Makefile
antivignettingtool.moc
autocorrectiontool.moc
cmake_install.cmake
digikamimageplugin_lenscorrection_automoc.cpp
digikamimageplugin_lenscorrection_automoc.cpp.files
imageplugin_lenscorrection.moc
klensfun.moc
lensdistortiontool.moc

Here's the console output when running digiKam... I can't find any relevant 'lenscorrection' stuff in it:

http://staff.washington.edu/rjsanyal/Photography/digiKam/digiKam_consoleoutput.txt

Please let me know if you have any more ideas.

Cheers,
Rishi
Comment 24 rishi.j.sanyal 2009-07-30 02:33:00 UTC
Oh, and just so you know-- I did undo my own changes to PGFplatform.h before applying your patch...

Rishi
Comment 25 caulier.gilles 2009-07-30 06:13:52 UTC
Lensfun plugin is not loaded in memory :

digikam(2digikam(25174)/digikam (core) Digikam::ImagePluginLoader::loadPluginsFromList: ImagePluginLoader: createInstance returned 0 for  "ImagePlugin_LensCorrection"  ( "digikamimageplugin_lenscorrection" )  with error:  "QLibrary::load_sys: Cannot load /opt/local/lib/kde4/digikamimageplugin_lenscorrection.so ()" 
5174)/digikam (core) Digikam::ImagePluginLoader::loadPluginsFromList: ImagePluginLoader: createInstance returned 0 for  "ImagePlugin_LensCorrection"  ( "digikamimageplugin_lenscorrection" )  with error:  "QLibrary::load_sys: Cannot load /opt/local/lib/kde4/digikamimageplugin_lenscorrection.so ()" 

I suspect that lensfun shared library used by lenscorrection plugin is corrupted on your computer...

Clean up lensfun code, recompile and install it properly, and do the same with  lenscorrection plugin.

Gilles Caulier
Comment 26 caulier.gilles 2009-07-30 06:16:32 UTC
SVN commit 1004398 by cgilles:

apply patch to prevent crash under Mac osx for intel
CCBUGS: 201302


 M  +6 -1      PGFplatform.h  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1004398
Comment 27 rishi.j.sanyal 2009-07-30 09:14:07 UTC
Oh, I see it now.

Sorry. I use a piece of $hit text editor called Text Wrangler which, apparently, can't even search for terms in a .txt file properly!

Will try to clean & reinstall & report back...

Thanks,
Rishi
Comment 28 caulier.gilles 2009-07-30 13:16:01 UTC
Ok, i close this file now, as crash is fixed...

Gilles
Comment 29 Marcel Wiesweg 2009-07-30 15:50:21 UTC
Rishi, we have another endianness problem open with PNG writing. Now that you have SVN trunk installed and running, would you mind helping us with testing bug #196692? That would be great. I have just committed a fix there but can't test obviously.
Comment 30 rishi.j.sanyal 2009-07-31 00:52:35 UTC
Hi Marcel,

Please clarify: do you want me to check out a particular revision & test compile it? If so, which revision?

Cheers,
Rishi
Comment 31 rishi.j.sanyal 2009-07-31 03:28:30 UTC
Gilles & to whomever else reading this that may be interested...

I found the problem with Lens Corrections plugin... basically, I had libiconv version 1.12 installed-- it needed to be upgraded to 1.13 so that libiconv.2.dylib (residing in /opt/local/lib) is version 8.0.0, not 7.0.0.

Now Lens Corrections & LensFun load fine...

Of course, these sort of problems arise b/c I can't update MacPorts to install the latest versions of everything, since I want to keep all KDE libs back at 4.2.0... *sigh* I don't even know where to begin in terms of what got broken in KDE libs 4.2.4...

Anyway, all seems to be working perfectly in Mac OS X, for revision 1004825 anyway!

Cheers,
Rishi
Comment 32 caulier.gilles 2009-07-31 11:45:37 UTC
Rishi,

As Marcel said, please continue to talk on this file :

https://bugs.kde.org/show_bug.cgi?id=196692

...and lets this one closed now. original problem about libpgf is fixed.

Marcel ask you to test current code from svn trunk under Macos-X, about to load and save PNG, TIFF, JPEG with editor.

Gilles Caulier
Comment 33 Marcel Wiesweg 2009-08-04 17:12:51 UTC
*** Bug 202430 has been marked as a duplicate of this bug. ***