I don’t have the time to fully track this down since I have a workaround, but I think I’ve found a feature deficiency in StringArray that results in uninitialized pointers occurring in what should be vanilla code.
[code]StringArray getFileExtensions() {
const tchar* const extensions[] = {
JUCE_T(".mp3"), JUCE_T(".mp2"), JUCE_T(".mp1"), NULL
};
return StringArray(extensions);
}
const StringArray& getFileExtensionsWorkaround() {
static StringArray fileExtensions = getFileExtensions();
return fileExtensions;
}[/code] then later[code]class Format : public AudioFormat {
public:
Format() : AudioFormat(getTranslatedName(), getFileExtensions()) {}
// …
};
void test() {
Format format;
}[/code]
Trying to instantiate Format results in an EXC_BAD_ACCESS signal (full stack trace given below) and when I dig down I see that the StringArray is pointing off into the clouds…
BUT if I simply replace the call to getFileExtensions() with getFileExtensionsWorkaround() then it all works - even though getFileExtensionsWorkaround() called getFileExtensions()…
I have a unit test that exhibits this, and it will be up on http://ax.to/swirlyjuce fairly shortly.
if you just used STL you wouldn’t have to keep reinventing the wheel - and fixing it when it fell off!
Actually, you should be using begin/end pairs to pass around lists of things, as those are “format agnostic” and work with pretty well any framework I’ve ever used in C++…
#0 0x0000aa66 in juce::Atomic::operator++ (this=0xfffffff4) at juce_Atomic.h:274
#1 0x001df08d in juce::StringHolder::retain (text=0x0) at /Users/tom/Documents/development/juce/Builds/MacOSX/…/…/src/text/juce_String.cpp:91
#2 0x001d9c1f in juce::String::String (this=0x4140000, other=@0x4140000) at /Users/tom/Documents/development/juce/Builds/MacOSX/…/…/src/text/juce_String.cpp:202
#3 0x001e258d in juce::Array<juce::String, juce::DummyCriticalSection>::Array (this=0xbffff2f4, other=@0xbffff2f4) at juce_Array.h:87
#4 0x001e1274 in juce::StringArray::StringArray (this=0xbffff2f4, other=@0xbffff2f4) at /Users/tom/Documents/development/juce/Builds/MacOSX/…/…/src/text/juce_StringArray.cpp:40
#5 0x0002daae in juce::AudioFormat::AudioFormat (this=0xbffff2ec, name=@0xbffff29c, extensions=@0xbffff2f4) at /Users/tom/Documents/development/juce/Builds/MacOSX/…/…/src/audio/audio_file_formats/juce_AudioFormat.cpp:517
#6 0x00027b0b in rec::audio::format::mpg123::Format::Format (this=0xbffff2ec) at Format.h:17
#7 0x000276b2 in rec::audio::format::mpg123::Format_IntFormat_Test::TestBody (this=0x14004d0) at /Users/tom/Documents/development/rec/unit-tests/…/src/rec/audio/format/mpg123/Format_test.cpp:17
#8 0x0054c568 in testing::Test::Run (this=0x14004d0) at gtest.cc:2095
#9 0x0054c653 in testing::internal::TestInfoImpl::Run (this=0x70d560) at gtest.cc:2314
#10 0x0054c796 in testing::TestCase::Run (this=0x70d620) at gtest.cc:2420
#11 0x0054caa6 in testing::internal::UnitTestImpl::RunAllTests (this=0x70b700) at gtest.cc:4024
#12 0x0054cc3c in testing::UnitTest::Run (this=0x578100) at gtest.cc:3687
#13 0x001eef2a in main (argc=1, argv=0xbffff4bc) at /Users/tom/Documents/development/gtest/xcode/…/src/gtest_main.cc:38