Page 1 of 2
					
				EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-04T18:00:26-07:00
				by eric_vi
				i am using a static version of imageMagick within a plug-in on Mac OS X.6 ..
i have no argv so I initialize image Magick this way:
Magick::InitializeMagick("");
when i try to open an image  i get a crash in
Code: Select all
MagickExport NexusInfo **AcquirePixelCacheNexus(const size_t number_threads)
{
  NexusInfo
    **nexus_info;
  register ssize_t
    i;
  nexus_info=(NexusInfo **) AcquireQuantumMemory(number_threads,
    sizeof(*nexus_info));
  if (nexus_info == (NexusInfo **) NULL)
    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
  for (i=0; i < (ssize_t) number_threads; i++)
  {
    nexus_info[i]=(NexusInfo *) AcquireAlignedMemory(1,sizeof(**nexus_info));
    if (nexus_info[i] == (NexusInfo *) NULL)
      ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
    (void) ResetMagickMemory(nexus_info[i],0,sizeof(*nexus_info[i]));
    nexus_info[i]->signature=MagickSignature;
  }
  return(nexus_info);
}
 
NOTE:
if i use the same code and same static imageMagick library within a standalone application, it works!
what am i missing?
Thanks for your help
 
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-04T18:16:59-07:00
				by magick
				We'll need a stack trace to help.  Do you have gdb?
Which version of ImageMagick are you using?
 
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-05T07:48:10-07:00
				by eric_vi
				it is version 6.6.7
i work thru xcode on OS X.6
here is the stack ImageMagick has not been used before apart from the InitializeMagick("") line
  this is when i do...      Image           magickImage;
i get
0 MagickExport NexusInfo **AcquirePixelCacheNexus
1 MagickExport Cache AcquirePixelCache
2 MagickExport Image *AcquireImage
3 Magick::ImageRef::ImageRef
4 Magick::Image::Image
when i trace ... i get the ThrowFatalException at this line
if (nexus_info == (NexusInfo **) NULL)
    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
so it seems the AcquireQuantumMemory that was executed just before did not returned anything
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-05T09:23:17-07:00
				by magick
				Can you trace the number_threads variable?  Is it 0 or some large value?  If not, it appears the application is running out of memory.
Can you try with the latest release of ImageMagick 6.7.8?
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-05T10:26:15-07:00
				by eric_vi
				hi thanks 
number of threads are 1... 
i cannot see how it can be running out of memory... what is the amount of memory needed.. is there a way i can check it?
i am not into an application i am within a dll, if i use the exact same within an application it works fine.
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-05T10:38:02-07:00
				by magick
				Its possible your application is corrupting memory.  Otherwise we're clueless.   We run a memory debugger on ImageMagick before each release to ensure its not corrupting memory.   And if ImageMagick's utilities work, it suggests ImageMagick is working properly.  You can run the unit tests with 'make check' as well as the PerlMagick tests with 'make test' and the PerlMagick demos in PerlMagick/demos.  If all these run, it suggests ImageMagick is stable.
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-05T10:50:32-07:00
				by eric_vi
				i know i am using a static version of imagemagick (this one!), inside applications  without problem... 
here in fact i am turning one of my application that uses imagemagick successfully into a dll... my dll works well but the call to imagemagick in this context does not.
i just tried to move the declaration at the real beginning, this way
	Magick::InitializeMagick("");
	Image           magickImage;
so not much has happened yet...  i get the exact same fatalerror
there is something in the way magick manages memory within a dll or an app that is done differently and does not seem to work
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-05T11:11:34-07:00
				by eric_vi
				i will try to download the latest and compile a new static set ( i remembered when i did it last time... it was not as easy as it sounded between thread and delegates issues!)
 is there some kind of flags  in the configure around the way malloc are done that i can set to avoid fancy memory management (if any!)
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-09T11:38:33-07:00
				by eric_vi
				i build a new static library with the latest 6.7.8 and linked to my dll,
 i am getting a similar error not at the same place...
it now occurs while doing Magick::InitializeMagick("");
here is the stack
#97978	0x17ae684dc in AllocateSemaphoreInfo at semaphore.c:200
#97979	0x17ae68575 in AcquireSemaphoreInfo at semaphore.c:102
#97980	0x17ae02660 in LogComponentGenesis at log.c:692
#97981	0x17ae07a5a in MagickCoreGenesis at magick.c:1230
#97982	0x17ad4a16b in Magick::InitializeMagick at Image.cpp:4273
and getting again a MemoryAllocationFailed fatal error, i am sure there are tons of memory when it happens, there must be something else which is related to those memory allocation within a dll
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-09T13:11:15-07:00
				by magick
				Try commenting out 
- #define MAGICKCORE_HAVE__ALIGNED_MALLOC 1
 
in 
magick/magick-config.h.  Rebuild ImageMagick and run.  Do you still get memory corruption?
 
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-11T20:24:00-07:00
				by eric_vi
				hi thank you, no more memory corruption... now i seem to have some issues reading images (does not work so far), but no more crash
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-12T06:22:44-07:00
				by magick
				If you have the time, download ImageMagick 6.7.8-9.  Does it cause memory corruption?  If so, the problem may be with the Windows _aligned_malloc() method or perhaps memory allocated with _aligned_malloc() is not being properly freed with _aligned_free() method.
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-12T08:00:48-07:00
				by eric_vi
				hello, thank you again, 
my try was with 6.7.8-8, i am on Mac OS X.6, i commented out the line you indicated... i can go through the  Magick::InitializeMagick(""); fine
but i am back to my original EXC_BAD_ACCESS in AcquirePixelCacheNexus...
which comes just after Magick::InitializeMagick("") when declaring Image.
this way:
InitializeMagick("");
Image magickImage;
at the real beginning of my DLL, so it might be memory alignment, from my experience it is very often some initialisation not done, 64bit pointer...
In another of my posts i had some issues with a posix_memalign link error, this was with the same program... this link error suddenly disappeared when i recreated the xcode project... but there might be some issues (just mentioning it in case that could give you some hints, since it seems close to this problem too)
i won't have much time this week but i will try what you suggest
 will 6-7-8-9 will make a difference with -8?
what else should i try to comment out?
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-12T08:27:53-07:00
				by magick
				We have a seen a few reports for Mac OS X concerning a  broken posix_memalign() implementation.  Comment out 
- #define MAGICKCORE_HAVE_POSIX_MEMALIGN 1
 
in magick/magick-config.h.  In the mean-time, we'll see if we can detect the broken implementation and hack around it in the ImageMagick source distribution.
 
			 
			
					
				Re: EXC_BAD_ACCESS in AcquirePixelCacheNexus
				Posted: 2012-08-25T08:17:33-07:00
				by eric_vi
				i finally had time to build a static version of 6.7.9-0  and linked it to my dll. i noticed that #define MAGICKCORE_HAVE__ALIGNED_MALLOC 1 is commented out in this version. Unfortunately when i am doing the
Magick::InitializeMagick(""); right after launching my DLL i get the exact same of crash... i am not exactly sure what else i can do