Browse Source

Fix a crash on shutdown when DanglingStreamChecker gets destroyed before LeakCounter instances.

tags/2021-05-28
Lukasz Kozakiewicz 6 years ago
parent
commit
4ff0c9c881
1 changed files with 14 additions and 3 deletions
  1. +14
    -3
      modules/juce_core/streams/juce_OutputStream.cpp

+ 14
- 3
modules/juce_core/streams/juce_OutputStream.cpp View File

@@ -25,9 +25,10 @@ namespace juce
#if JUCE_DEBUG
//==============================================================================
struct DanglingStreamChecker
{
DanglingStreamChecker() {}
DanglingStreamChecker() = default;
~DanglingStreamChecker()
{
@@ -38,12 +39,20 @@ struct DanglingStreamChecker
nastiness..
*/
jassert (activeStreams.size() == 0);
// We need to flag when this helper struct has been destroyed to prevent some
// nasty order-of-static-destruction issues
hasBeenDestroyed = true;
}
Array<void*, CriticalSection> activeStreams;
static bool hasBeenDestroyed;
};
bool DanglingStreamChecker::hasBeenDestroyed = false;
static DanglingStreamChecker danglingStreamChecker;
#endif
//==============================================================================
@@ -51,14 +60,16 @@ OutputStream::OutputStream()
: newLineString (NewLine::getDefault())
{
#if JUCE_DEBUG
danglingStreamChecker.activeStreams.add (this);
if (! DanglingStreamChecker::hasBeenDestroyed)
danglingStreamChecker.activeStreams.add (this);
#endif
}
OutputStream::~OutputStream()
{
#if JUCE_DEBUG
danglingStreamChecker.activeStreams.removeFirstMatchingValue (this);
if (! DanglingStreamChecker::hasBeenDestroyed)
danglingStreamChecker.activeStreams.removeFirstMatchingValue (this);
#endif
}


Loading…
Cancel
Save