juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.
https://juce.com
Other
6.36k stars 1.68k forks source link

[Bug]: (JUCE 8) Segmentation Fault When Creating New Typeface in Static Function on Linux #1406

Closed Lunix-420 closed 1 week ago

Lunix-420 commented 2 weeks ago

Detailed steps on how to reproduce the bug

  1. Create a static function that returns a Typeface::Ptr by calling Typeface::createSystemTypefaceFor.
    static Typeface::Ptr getCustomTypeface()
    {
    return Typeface::createSystemTypefaceFor(
        BinaryData::CustomFont_ttf, BinaryData::CustomFont_ttfSize);
    }
  2. Call the getCustomTypeface function.
  3. Observe that a segmentation fault occurs at this line:
    
    // juce/modules/juce_core/text/juce_CharPointer_UTF8.h 

/* Returns true if this pointer is pointing to a null character. / bool isEmpty() const noexcept { return *data == 0; }


**Note:** Using fonts only as non-static public members does not cause this problem.

### What is the expected behaviour?

Creating a new Typeface as a static variable should not cause a segmentation fault. The Typeface should be created and used without causing the application to crash. This behavior works as expected on Windows and macOS.

### Operating systems

Linux

### What versions of the operating systems?

Arch Linux x86_64 using Wayland (Kernel 6.9.7) 

### Architectures

x86_64

### Stacktrace

```shell
juce::CharPointer_UTF8::isEmpty(const juce::CharPointer_UTF8 * const this) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/text/juce_CharPointer_UTF8.h:81)
juce::String::isEmpty(const juce::String * const this) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/text/juce_String.h:335)
juce::StringPool::getPooledString(juce::StringPool * const this, const juce::String & newString) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/text/juce_StringPool.cpp:144)
juce::Identifier::Identifier(juce::Identifier * const this, const juce::String & nm) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/text/juce_Identifier.cpp:58)
juce::XmlElement::createTextElement(const juce::String & text) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/xml/juce_XmlElement.cpp:967)
juce::XmlDocument::readChildElements(juce::XmlDocument * const this, juce::XmlElement & parent) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/xml/juce_XmlDocument.cpp:662)
juce::XmlDocument::readNextElement(juce::XmlDocument * const this, const bool alsoParseSubElements) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/xml/juce_XmlDocument.cpp:453)
juce::XmlDocument::readChildElements(juce::XmlDocument * const this, juce::XmlElement & parent) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/xml/juce_XmlDocument.cpp:562)
juce::XmlDocument::readNextElement(juce::XmlDocument * const this, const bool alsoParseSubElements) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/xml/juce_XmlDocument.cpp:453)
juce::XmlDocument::parseDocumentElement(juce::XmlDocument * const this, juce::String::CharPointerType textToParse, bool onlyReadOuterDocumentElement) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/xml/juce_XmlDocument.cpp:231)
juce::XmlDocument::getDocumentElement(juce::XmlDocument * const this, const bool onlyReadOuterDocumentElement) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/xml/juce_XmlDocument.cpp:150)
juce::parseXML(const juce::File & file) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/xml/juce_XmlDocument.cpp:60)
juce::findFontsConfFile() (/data/dev/audio/oscilloscope/external/juce/modules/juce_graphics/native/juce_Fonts_linux.cpp:46)
juce::FTTypefaceList::getDefaultFontDirectories() (/data/dev/audio/oscilloscope/external/juce/modules/juce_graphics/native/juce_Fonts_linux.cpp:61)
juce::FTTypefaceList::FTTypefaceList(juce::FTTypefaceList * const this) (/data/dev/audio/oscilloscope/external/juce/modules/juce_graphics/native/juce_Fonts_freetype.cpp:137)
juce::SingletonHolder<juce::FTTypefaceList, juce::DummyCriticalSection, false>::getWithoutChecking(juce::SingletonHolder<juce::FTTypefaceList, juce::DummyCriticalSection, false> * const this) (/data/dev/audio/oscilloscope/external/juce/modules/juce_core/memory/juce_Singleton.h:115)
juce::FTTypefaceList::getInstance() (/data/dev/audio/oscilloscope/external/juce/modules/juce_graphics/native/juce_Fonts_freetype.cpp:323)
juce::FreeTypeTypeface::from(juce::Span<std::byte const, 18446744073709551615> data, int index) (/data/dev/audio/oscilloscope/external/juce/modules/juce_graphics/native/juce_Fonts_freetype.cpp:417)
juce::Typeface::createSystemTypefaceFor(juce::Span<std::byte const, 18446744073709551615> data) (/data/dev/audio/oscilloscope/external/juce/modules/juce_graphics/native/juce_Fonts_freetype.cpp:581)
juce::Typeface::createSystemTypefaceFor(const void * fontFileData, size_t fontFileDataSize) (/data/dev/audio/oscilloscope/external/juce/modules/juce_graphics/fonts/juce_Typeface.cpp:566)
frame::Settings::Fonts::getLightTypeface() (/data/dev/audio/oscilloscope/external/frame/utility/Settings.h:164)
__static_initialization_and_destruction_0() (/data/dev/audio/oscilloscope/external/frame/utility/Settings.h:177)
_GLOBAL__sub_I_PluginProcessor.cpp(void)() (/data/dev/audio/oscilloscope/src/app/PluginProcessor.cpp:210)
libc.so.6!__libc_start_main (Unknown Source:0)
_start (Unknown Source:0)

Plug-in formats (if applicable)

Standalone

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

The bug is present on the develop branch

Code of Conduct

reuk commented 1 week ago

Thanks for this report. We've fixed the issue on the develop branch: https://github.com/juce-framework/JUCE/commit/1023f62338a108c792e982ae30eeee48010bf117