LocalisedStrings crashes when TRANS static String


Steps to Reproduce:

  1. In your JUCE application, create a static string and attempt to use the translate macro to initialize the string.
  1. Compile and Run

  2. For me, I get an unhandled exception error with no call stack available. The break is in this function in juce_win32_Threads.cpp

void CriticalSection::enter() const throw() { EnterCriticalSection ((CRITICAL_SECTION*) internal); }

I am a fairly new C++ programmer, and a software developer intern at LOUD Tech, so I am not exactly sure what the problem is.

When the TRANS macro is called, it goes to this function in juce_LocalisedStrings.cpp

[code]void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations) throw()
const ScopedLock sl (currentMappingsLock);

delete currentMappings;
currentMappings = newTranslations;


it creates the ScopedLock object, which as soon as it’s created apparently locks the critical section. only to be unlocked when the object is deleted.

Like I said… I really am not sure what is going on, I’ve only had an introduction to the concepts of multi threaded C programs, Any help anyone could offer would be amazing! :smiley:

I’ll answer any other questions related to the problem as well, but for now I have no other pertinent information about the problem.


Constructors for objects with static storage duration execute before main() is called. So Juce is not fully initialized when the TRANS macro is evaluated.

Put your static objects into their own class, and create the class using operator new in your JUCEApplication-derived class.


Thank you so much!


I’ve been having alot of trouble implementing this, which I thought would be relatively simple… I created a Stack Overflow thread for it… Do you think you could take a look and give me your advice?


If you put your static variable inside a function, and make sure that the function isn’t called until the program has finished initialising, then you can call TRANS inside it with no problem.

And please stop using the T() macro! It’s deprecated, and I don’t use it anywhere in the library any more - at some point I’m going to remove it!


Yes, please do, the sooner the better.
T() is one of the usual pain with juce and win32 in general as it break template code almost everywhere (so many people use T and U for template parameters).