Juce::string issues


#1

Here are a couple of issues with juce::String that we have encountered.

Juce version 1.53
platform: Windows 7 64-bit

Scenario 1

Issue: Thread A copies a juce::String into a struct, and passes that struct to a different thread through a locked juce::Array. The other thread uses the string, which contains a file path, to memory map a file, so the string is converted to wide characters. A crash would happen intermittently (after 1-2 minutes of program use) in thread A, inside the Array’s enter critical section method.

Solution: Instead of copying the juce::String into the struct, allocating a char* and copying the characters manually, then creating a String from it in Thread B right before opening the file made the problem go away.

Scenario 2

Issue: Multiple threads call file.existsAsFile as the same time. The file objects are different, but contain the same path. The project will often crash inside makeUniqueWithByteSize(const CharPointerType& text, size_t numBytes) During the execution of the function, text will end up changing, causing the function to crash inside the memcpy

Solution: Place a lock before the call to file.existsAsFile()

bool foo::exists
{
ScopedLock lock(doesFileExistLock);
return file.existsAsFile();
}

John Lawrie


#2

The string class should be thread-safe in those circumstances, but it has changed a lot internally since 1.53.

Please always try the latest version before reporting bugs…