Strange crash occurring in release when constructing juce::CriticalSection

Hi Jucers,

I seem to be experiencing a really strange crash that only occurs on MacOS in release mode. It’s been really difficult to track down but I have managed to figure out where it is happening.

I have a class that is being loaded when it crashes and this class has a juce::CriticalSection as a member variable. I have commented out all of the places that the CriticalSecion is used and if I remove the CriticalSection member variable from the class then I do not experience a crash.

It’s a very strange problem. Does anyone know how adding a juce::CriticalSection to a class could cause a crash only in run mode on MacOS?

Any help would be much appreciated!

Cheers,

Chris

I suspect we will have to see more source code to be able extrapolate what the issue might be.

+1 what @cpr2323 said.

But most of the times I see these kinds of crashes in my own work it’s a lifetime problem. Could it be that one thread is accessing an object that is already deleted (by another thread)?

What’s the last entry in your callstack that contains code that you wrote? Going backwards a few steps at most from this screen should give you better information on where this is occuring.

Thanks @cpr2323 & @benediktadams for your replies.

Unfortunately, I think that the code might be a bit difficult to post on here as there is quite a bit going on. However, I know that the code that is triggering the error is being used elsewhere with no problems.

I guess that differences in timings between different platforms could be the reason that the bug shows up on the MacOS release build only. As @benediktadams said it seems likely that something is being deleted in another thread. I will keep digging! :slightly_smiling_face: :+1:

I had a recent crash that occurred because a CriticalSection was being unlocked twice. I was trying to take advantage of a ScopedLock AND manual unlocking. ie. there was one exit path that needed to sleep, so I had to manually unlock for this (so as not to hold the locks during the sleep). BUZZ! not going to work… lol… but I did come up with a super creative generic solution for executing a lambda on scope exit (JUCE should add one) which I called ScopedExitFunction… anyways, just mentioning the problem is case it helps think about where the issue might be.

2 Likes

Hey Guys,

It took a lot of digging around and I didn’t ever really figure out what the problem was in the end. I couldn’t find anything that was being deleted in another thread and it was extremely difficult to debug when the crash was only occurring in release mode.

I had resolved all of the standard warnings during build so I eventually decided to run CPP Check on my code and fixed a bunch of errors and warnings. Quite a few of them were due to class members not being initialised in the constructor. Anyway, whatever the problem was now seems to be resolved. :raised_hands: :raised_hands: :raised_hands:

Thanks for your help!

Chris