EditLoader: Destructor hangs if loading failed

E.g. something like this

File invalidFile;
bool done = false;
auto editLoader =
    te::EditLoader::loadEdit (*engine, invalidFile, [&done] (auto) { done = true; });

while (! done)
    Thread::sleep (20);

editLoader.reset();

will hang forever at the last line.

I think the problem is here:

EditLoader::Handle::~Handle()
{
    cancel();

    if (! loadContext.completed)
        signalThreadShouldExit (loadThread.get_id());

    loadThread.join();
}

where loadContext.completed is not set if load has failed, but the thread will have finished and so calling signalThreadShouldExit will hang as the thread id is not registered anymore.

Thanks for the report and the test case, that made it super quick for me to replicate.

It was actually way more subtle than I first thought but I think this should be fixed now here:

Let me know if you see any other problems with it.

1 Like

I see! But yes it works now - thanks!

Great, thanks for the report :+1: