This has been a frustrating issue for my program for a long time, and I finally traced the issue down. I'm using CMake's BundleUtilities to bundle GraphicsMagick into my app bundle, but every time that I use it, my application will crash with the following failed assertion:
Assertion failed: (semaphoreinfo != (SemaphoreInfo ) NULL), function LockSemaphoreInfo, file magick/semaphore.c, line 601.
I wouldn't get this issue when I manually copied the .dylib files, and even when I changed all of the linker paths to link my bundle's libraries, such as @executable_path/../Libraries/libwhatever.0.dylib. It's when I change the library's ID to the bundle's library path, which is a part of the BundleUtilities process. I'm running InitializeMagick(ExecutablePath); (where ExecutablePath == "lightpad.app/Contents/MacOS/lightpad") at the very beginning of my program.
Something much deeper within GraphicsMagick that's beyond my knowledge of its code must be going on. This has been something that has stumped me for weeks, and delayed deployment of the mentionned application, Lightpad. If it helps, I have version 1.3.26, which I've installed using Homebrew. I'm more than happy to provide any additional information needed for this!
Since you are invoking InitializeMagick(), the most likely cause of problems like this could be if there are multiple GraphicsMagick shared libraries/headers and the wrong ones are being used when compiling, linking, or at run-time. There is also the possibility of mixing header files from two different GraphicsMagick builds. CMake might not be making it obvious what it is doing.
At the shell prompt do:
export MAGICK_DEBUG=configure
and run your program from that shell prompt. You should see a trace of everything which is done to find GraphicsMagick files. It should then be obvious if it is looking for files in places other than you anticipated. If it instantaneously crashes, then you have a problem other than file locations.
Make sure that you configured GraphicsMagick with the '--disable-installed' option so that it searches based on the location of the invoking program or GraphicsMagick shared library rather than using hard-coded paths. In this case, the GraphicsMagick files need to be co-located with the using application in a particular way. Since OS X is a Unix type system, I think that the files would be co-located in sub-directories similar to how they would be installed under an installation 'prefix'.
Since I only have one version of GraphicsMagick installed on my machine (and I just updated to 1.3.27, completely uninstalling 1.3.26), we can eliminate that as a result. I just went ahead and attempted to use the
--disable-installedargument (as well as set theMAGICK_DEBUGenvironment variable) to see if that would fix anything. No luck, unfortunately. I had a slightly different result at first, where it aborted due to being unable to find all the .mgk files, but I manually copied those files over and re-ran. Then it would give me the same assertion.Something I notice is that it seems to crash right after loading
png.laand callingRegisterPNGImagethenUnregisterPNGImage. I'm loading PNGs into my project at the time when I start to utilize GraphicsMagick (which is the exact time of crash), maybe that has something to do with it? I have copiedGraphicsMagick/lib/GraphicsMagickover intolightpad.app/Contents/lib/GraphicsMagickwithout modifying any of the files, so the library will find them. The full log can be found here, if it helps!On the subject of the hard-coded paths, I personally feel that they should be avoided as much as possible. If you're able to determine the path of the library and where it's required files are, why not simply use that all the time? (Of course, this may just be me -- I'm one of those that leans towards the simplest of answers. :P)
On Tue, 19 Dec 2017, Vinyl Darkscratch wrote:
That does look suspicious.
Your debug log appears so show that files (e.g. log.mgk) are not at
expected places.
Does only PNG fail and other formats appear to work?
What does
grep SETJMP_IS_THREAD_SAFE magick/magick_config.h
in the build directory show?
Did you do 'make check' after doing a compile to make sure that the
test suite passes?
The best way to get the GraphicsMagick files into a form suitable for
using is to do
mkdir /path/to/tmp/installdir
make DESTDIR=/path/to/tmp/installdir install
and then you should have installed files under
'/path/to/tmp/installdir'. The installed files will have a different
layout than in the build directory. For the "installed" case you
would want to replicate starting at 'installdir' and you could put
your own binary in 'installdir/bin'.
Bob
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
For
log.mgk, I actually don't see this file anywhere on my system. Perhaps it wasn't included in my particular install?A quick
grepofmagick/magick_config.hshowed no results forSETJMP_IS_THREAD_SAFE(Homebrew builds the formulas on their own servers and deploys pre-built "bottles", so I ran this in the install directory instead).I also looked at the formula, however, and it seems that there's no call to
make checkin the test stage. Adding that and submitting a PR to get that fixed...One of the issues that I'm seeing here is that I wish to utilize Homebrew for dependency management, as does my CI of choice, Travis CI. What it could be, is that the GraphicsMagick Homebrew formula has some issues that need to be resolved. I'll attempt to compile this directly from the source download, and report any changes I find, as well as update the Homebrew formula.
Last edit: Vinyl Darkscratch 2018-01-02
On Mon, 1 Jan 2018, Vinyl Darkscratch wrote:
This file is delivered with GraphicsMagick source code in the 'config'
subdirectory. It is always installed. It is the first file which is
attempted to be read and without the file, there are baked-in
defaults.
This definition was added for 1.3.27 but you seem to be using 1.3.26.
I am not sure what this CMake and Homebrew build formula is doing.
Perhaps it is applying patches or using a completely different build
methodology. You say that it is built on a 'server' so perhaps the
binary product is not compatible with the final execution environment.
If you can post the full output of 'gm convert -version' then it is
possible that something useful may be revealed.
Bob
I see
log.mgkin the source code now, it's strange that it wouldn't be included in the install directory... What's even weirder, the Homebrew formula isn't applying any patches to the code.Actually, I've upgraded to 1.3.27 now. I was under the assumption that some of the problems I'm facing may be related to having the older version, plus hey, bug fixes and enhancements are always helpful! My
grepwas on the version for 1.3.27.I posted the results of
gm versionin my last response, though it was an edit, so it didn't show in the email. I moved it into this response instead. The command displays the following results:The
--prefix=/usr/local/Cellar/graphicsmagick/1.3.27looks suspicious -- perhaps if we remove it, we may obtain better results?On Tue, 2 Jan 2018, Vinyl Darkscratch wrote:
I do see that there are no patches. I also see that the script ends
with "make install" and there is just one trivial sanity test of its
own design rather than using the built-in test suite.
There must be some other script/definition which bundles up the result
of "make install" so that it can actually be installed.
Bob
Any more information on this issue? A stack backtrace of a core dump using a debugger would be useful to identify where the problem is occuring. A response to my prior questions is appreciated. At the moment I have nothing to go on so I don't know how to help.
First off, thank you for all of your help on this matter! Second, I apologize for not responding, I have just returned from a week-long vacation visiting relatives, and decided that it would be better to take a break from the project during that time so I can clear my mind.
That...and it seems I've run into some issues with CMake linking a certain library, though it's one I'm wanting to get rid of anyways so perhaps it's a sign from my computer saying "hey, remove this sooner than later!"
I will post my findings based upon your suggestions shortly!
Last edit: Vinyl Darkscratch 2018-01-01
A little bit of information that may help: when
--disable-installedis included, the program crashes once I attempt to utilize GraphicsMagick in any way. Also, removing the--prefixoptions causes some issues with the install step, since it's attempting to install to the typical folders, rather than remain in Brew's "Cellar" (which symlinks files into /usr/local as needed), so that must stay.I still need to try compiling and installing it without using Homebrew. That's been big on my to-do list for quite a while...
Unless further useful information such as a debugger backtrace is provided, I will be closing this issue soon since I have no way to reproduce it.
Requested information was not provided by reporter.
Finally got around to this, whew! So, I've eliminated it being an issue with Homebrew -- I tried to compile and install it from the source, and got the same issues during bundling. I tried with a different series of arguments, however, and had gotten satisfactory results. So, it's something to do with the specific arguments passed in, it looks like.
To compare them, here's the arguments (as reported by 'gm version') between the failing version and the working one:
Failing:
./configure '--prefix=/usr/local/Cellar/graphicsmagick/1.3.28_1' '--disable-dependency-tracking' '--enable-shared' '--disable-static' '--with-modules' '--without-lzma' '--disable-openmp' '--with-quantum-depth=16' '--without-gslib' '--with-gs-font-dir=/usr/local/share/ghostscript/fonts' '--with-webp=no' '--without-x' '--without-lcms2' '--without-wmf' 'CC=clang' 'CXX=clang++'Working:
./configure '--enable-shared' '--with-quantum-depth=16' '--prefix=/Users/vinyldarkscratch/Developer/Nightwave/lightpad/graphicsmagick/' '--without-x' '--with-png'Further research into the matter is required, which I will, of course, be conducting.
Last edit: Vinyl Darkscratch 2018-02-20