I'm trying to integrate Juce 3.0.0-39-g488fe56 into an existing C++ proof-of-concept project that was never completed by a previous developer.
I'm getting a segfault deep in Juce when I try to use a new class I wrote that inherits from juce::ApplicationProperties. I don't understand the Juce code which segfaults, but I suspect it could be due to this being called from a static object before main() has run and before Juce has been initialized.
I've read in the past some posts on the forum about using static objects, and I understand the problems and objections. But with a large pre-existing project where I don't have a choice without having to re-write how the code works, is there a call I can make so Juce is fully initialized? Or is there another cause to this problem?
Valgrind prints out the following:
==00:00:00:07.151 23732== Invalid read of size 4 ==00:00:00:07.151 23732== at 0x6E6E27: juce::Atomic<int>::operator++() (/projects/WorkOrder/JuceLibraryCode/modules/juce_graphics/../juce_core/memory/juce_Atomic.h:327) ==00:00:00:07.151 23732== by 0x6E13B0: juce::StringHolder::retain(juce::CharPointer_UTF8) (/projects/WorkOrder/JuceLibraryCode/modules/juce_core/text/juce_String.cpp:168) ==00:00:00:07.151 23732== by 0x6A213E: juce::String::operator=(juce::String const&) (/projects/WorkOrder/JuceLibraryCode/modules/juce_core/text/juce_String.cpp:264) ==00:00:00:07.151 23732== by 0x6B13F0: juce::XmlDocument::parseDocumentElement(juce::CharPointer_UTF8, bool) (/projects/WorkOrder/JuceLibraryCode/modules/juce_core/xml/juce_XmlDocument.cpp:213) ==00:00:00:07.151 23732== by 0x6B0FDD: juce::XmlDocument::getDocumentElement(bool) (/projects/WorkOrder/JuceLibraryCode/modules/juce_core/xml/juce_XmlDocument.cpp:142) ==00:00:00:07.151 23732== by 0x704098: juce::PropertiesFile::loadAsXml() (/projects/WorkOrder/JuceLibraryCode/modules/juce_data_structures/app_properties/juce_PropertiesFile.cpp:182) ==00:00:00:07.151 23732== by 0x703B60: juce::PropertiesFile::reload() (/projects/WorkOrder/JuceLibraryCode/modules/juce_data_structures/app_properties/juce_PropertiesFile.cpp:129) ==00:00:00:07.151 23732== by 0x703A4F: juce::PropertiesFile::PropertiesFile(juce::PropertiesFile::Options const&) (/projects/WorkOrder/JuceLibraryCode/modules/juce_data_structures/app_properties/juce_PropertiesFile.cpp:119) ==00:00:00:07.151 23732== by 0x703389: juce::ApplicationProperties::openFiles() (/projects/WorkOrder/JuceLibraryCode/modules/juce_data_structures/app_properties/juce_ApplicationProperties.cpp:54) ==00:00:00:07.151 23732== by 0x70349B: juce::ApplicationProperties::getUserSettings() (/projects/WorkOrder/JuceLibraryCode/modules/juce_data_structures/app_properties/juce_ApplicationProperties.cpp:70) ==00:00:00:07.151 23732== by 0x65F6E7: WO::Config::getString(juce::String const&, juce::String const&) (/projects/WorkOrder/src-config/WOConfig.cpp:55) ==00:00:00:07.151 23732== by 0x65F619: WO::Config::operator(juce::String const&) (/projects/WorkOrder/src-config/WOConfig.cpp:48) ==00:00:00:07.151 23732== by 0x6564AF: WO::DatabaseAccess::DatabaseAccess(std::string const&) (/projects/WorkOrder/src-base/DatabaseAccess.cpp:19) ==00:00:00:07.151 23732== by 0x65E6E9: __static_initialization_and_destruction_0(int, int) (/projects/WorkOrder/src-base/StaticObjects.cpp:71) ==00:00:00:07.151 23732== by 0x65E75C: _GLOBAL__sub_I__Z8initJucev (/projects/WorkOrder/src-base/StaticObjects.cpp:72) ==00:00:00:07.151 23732== by 0x93801C: __libc_csu_init (in /home/stephane/projects/WorkOrder/build/src-wo/wo) ==00:00:00:07.151 23732== by 0x697BE34: (below main) (/build/buildd/eglibc-2.17/csu/libc-start.c:219) ==00:00:00:07.151 23732== Address 0xfffffffffffffff0 is not stack'd, malloc'd or (recently) free'd
In gdb, I see this:
325 #elif JUCE_ATOMICS_GCC 326 return sizeof (Type) == 4 ? (Type) __sync_add_and_fetch (&value, (Type) 1) 327 : (Type) __sync_add_and_fetch ((int64_t*) &value, 1); 328 #endif (gdb) print value Cannot access memory at address 0xfffffffffffffff0
...with the error on line 327.