Which works fine when there is an internet connection. However, when there isn’t a connection on OSX (still need to try in Windows), after a while this provokes an assertion failure in stopThread:
void Thread::stopThread (const int timeOutMilliseconds)
{
// agh! You can't stop the thread that's calling this method! How on earth
// would that work??
jassert (getCurrentThreadId() != getThreadId()); // <----------- here!
...
}
More particular, the stopThread comes from juce_mac_Network.mm:
I don’t think that we’re doing something “special”, so I’m wondering if anyone has any ideas about this! I suppose the problem might arise from using the thread pool job? Is there a better way to do this?
I just refactored that code this morning… Can you give it a shot with the new version and let me know if it helps! If not, I’ll take a deeper look at it.
Same error occurred… I have to add though that this is a very, very sporadic error, so it’s pretty hard to debug/find!
I’m going to make a tiny test app with only my URL getting job to see if I can reproduce it more faithfully.
Let me know if you find anything, I’ll report back when I have that app…
below is a simple test app to reproduce… While doing this test I uncovered another error for you to have a look at… If you run this code multiple times (tested on windows for now), you sporadically get:
JUCE Assertion failure in d:\dev\juce\modules\juce_core\memory\juce_leakedobjectdetector.h, line JUCE Assertion failure in d:\dev\juce\modules\juce_core\memory\juce_leakedobjectdetector.h, line 71
JUCE Assertion failure in d:\dev\juce\modules\juce_core\memory\juce_leakedobjectdetector.h, line 71
JUCE Assertion failure in d:\dev\juce\modules\juce_core\memory\juce_leakedobjectdetector.h, line 71
71
<more of the same>
JUCE Assertion failure in d:\dev\juce\modules\juce_core\memory\juce_leakedobjectdetector.h, line 71
JUCE Assertion failure in d:\dev\juce\modules\juce_core\memory\juce_referencecountedobject.h, line 84
Here’s the simple app I’m using to uncover both the OSX bug and this leak bug (run with your network disconnected!):
On OSX: yup, looks like its fixed!
On windows: still getting the mem leaks ( JUCE Assertion failure in d:\dev\juce\modules\juce_core\memory\juce_leakedobjectdetector.h, line 71 ) - but don’t really care about that right now
I did manage to reproduce it, but I don’t think It’s a real bug. What I think is happening is this:
You simultaneously kick off a bunch of threads which all try to create a URL, which involves MemoryBlocks, HeapBlocks etc. Because none of those classes have been created before at this point in your program, your threads are all in a race to be the first to use them. That’s normally fine BUT each class’s leak detector has a function-local static counter that all these threads need to use. On OSX, the compiler automatically locks the creation of all static objects, but on windows, it doesn’t. So I think what you’re seeing is the leak-counters getting messed up when two threads overlap in initialising one of these static counters.
It’s easy enough to see if I’m right, by just doing a dummy URL open/close BEFORE you create your thread pool - that will make sure that all the statics are safely ready to use.