Question

I have successfully managed to install MathGL on Mac OS and managed to get the mglGraph to generate me the sample graphs. Yet when I try to use mglData to handle my data, it crashes with an "EXC_BAD_ACCESS" error. Why? Is there anything I need to do I haven't done?

I installed mathgl with cmake, make and make install (using sudo to be on the safe side). Then I added the /usr/local/include and /usr/local/lib paths to the project and added the libmgl.dylib and libmgl-wnd.dylib references to the project. Is there anything I've missed out? I could not find anybody else with the error (well, I found many bad access errors, but none caused by mglData). The error pops up as soon as I'm trying to construct a mglData instance, so any of this triggers the exception:


mglData *data = new mglData();
mglData data;
etc...

EDIT

So, here's the bare bone of my code that compiles but crashes:


#include iostream
#include mgl2/mgl.h

int main(int argc, const char * argv[])
{
    mglData y;   
    return 0;
}

The thread's call stack when it crashes is:

Thread call stack

And the values of all variables are this:

Variable values


Semi-Solved Got it running

After having been able to compile my project with g++, I tried changing the build settings and who would have believed it, I managed to get it running! All I did was change the C++ Standard Library to libstdc++ (GNU C++ standard library). Now I'm not using the default, which is to use libc++ (LLVM C++ standard library with C++ 11 support). At the moment this seems to work fine for my Cocoa application also, but I don't know for how long :P (When using more NS* Classes I worry LLVM may be necessary?)

Still I'm very interested in how this issue can be resolved (without having to change the build settings) or whether it can't.

No correct solution

OTHER TIPS

I'm working with mathgl 2.1.2 and ran into the same problem. There's a mismatch between the run-time libraries. Mathgl uses compiler default but when creating a new commas-libe project it uses the llvm. Since the string is allocated in your executable via LLVM, but then passed to Mathgl which used a different run-time library. Memory operations can fail when a pointer allocated in one library is passed to another to be freed. There could be structure differences as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top