ASIO buffers disposal

I am getting a crash in the asioObject->disposeBuffers() call, in juce_win32_ASIO.cpp l.1060.
This happens when I select an ASIO device whose hardware is not connected. Seems to happen with various ASIO drivers from different audio interfaces.
I noticed that in this case we end up calling disposeBuffers() after a failure of initDriver(): what I don’t understand is why should we release the buffers since they have not been allocated (and the drivers is even not initialized).
Skipping that call seems to solve the problem in this case. What do you think ?

1 Like

Interesting, thanks! I guess I was kind of assuming that devices would just ignore the disposeBuffers call if they didn’t have any buffers to dispose - it always amazes me how flakey ASIO drivers seem to be! I mean… seriously, when you’re writing a public function that will be called from 3rd party code, it’s just unprofessional to not give it some rudimentary safety checks.

Anyway, rant over. I guess I’ll change that. Your line number doesn’t correspond to my latest code, so I guess you’re talking about the call at the end of openDevice()? In which case, skipping it is actually (probably) ok, as the driver is about to get deleted anyway. Of course, there’s also the risk that there are a whole bunch of other flakey drivers which will crash if you try to delete them without calling disposeBuffers!

Yes I’m talking about the call at the end of openDevice().
Since this problem does not appear with all drivers but only some of them, maybe the best solution is to call disposeBuffers() only if the buffers have been successfully created via the createBuffers() function, by saving some kind of boolean.

And yes, I agree that they should have implemented that kind of basic checks in their driver!

Picking this up again…
I have some drivers that crash. Reports from vendor was:
Please check:
1) CreateBuffers was called before DisposeBuffers
2) The ASIO driver is stopped and is in the Prepared state before calling DisposeBuffers, i.e. don’t call DisposeBuffers outside the Prepared state.

The last asio log I get from these drivers are "ASIO: disposing buffers"
Looking in to the code now I see at least one thing that I don’t understand:

There is this method

void disposeBuffers()
    if (asioObject != nullptr && buffersCreated)
        buffersCreated = false;

But that is just used one ot two placese all other places call asioObject->disposeBuffers(); direclty with out the checks and conditions. Is there a reason for this inconsistency ?