URL::createInputStream crash


#1

If I run the following code in a freshly created Console Application on OSX I always crash on quit (so after the return 0 line, in a different thread than the main thread.

This code is adapted from JuceDemo.

int main (int argc, char* argv[])
{
	URL url {"https://www.google.com"};
	StringPairArray responseHeaders;
	int statusCode = 0;
	ScopedPointer<InputStream> stream ( url.createInputStream (false,  nullptr, nullptr,  String(),  10000, &responseHeaders, &statusCode) );
	if (stream != nullptr)
	{
		String result = stream->readEntireStreamAsString();
		DBG( (statusCode != 0 ? "Status code: " + String (statusCode) + newLine : String())
			+ "Response headers: " + newLine
			+ responseHeaders.getDescription() + newLine
			+ "----------------------------------------------------" + newLine
			+ result );
	}
	else if (statusCode != 0)
	{
		DBG( "Failed to connect, status code = " + String (statusCode) );
	}
	else DBG( "Failed to connect!" );
        return 0;
}

Anyone any insights?


#2

When you say “crash” do you really mean “assert”?


#3

nope: EXC_BAD_ACCESS

there are around 8-10 threads still alive, one of them called com.apple.NSURLConnectionLoader
It crashes in a different places and threads on different runs.


#4

Xcode 9.2,
OSX 10.12.6
JUCE 5.2.0


#5

Well, I asked because clearly you’re just exiting without actually clearing up all the threads that will be active, and I’d expect that to cause assertions in at least the juce threads.

Try using a juce::ScopedJuceInitialiser_GUI ?


#6

yup, that solves it.