Hey, I currently encounter a bug with VL.IO.Midi, MidiIn
.
When having a MidiIn
in the patch, the vvvv process stays alive when closing vvvv.
Debugged it with VS and the process hangs inside Sanford.Multimedia.Midi DelegateQueue.DelegateProcedure()
at Monitor.Wait(lockObject) because the InputDevice is not disposed.
private void DelegateProcedure()
{
lock(lockObject)
{
// Signal the constructor that the thread is now running.
Monitor.Pulse(lockObject);
}
// Set this DelegateQueue as the SynchronizationContext for this thread.
SynchronizationContext.SetSynchronizationContext(this);
// Placeholder for DelegateQueueAsyncResult objects.
DelegateQueueAsyncResult result = null;
// While the DelegateQueue has not been disposed.
while(true)
{
// Critical section.
lock(lockObject)
{
// If the DelegateQueue has been disposed, break out of loop; we're done.
if(disposed)
{
break;
}
// If there are delegates waiting to be invoked.
if(delegateDeque.Count > 0)
{
result = delegateDeque.PopFront();
}
// Else there are no delegates waiting to be invoked.
else
{
// Wait for next delegate.
Monitor.Wait(lockObject);
// If the DelegateQueue has been disposed, break out of loop; we're done.
if(disposed)
{
break;
}
[...]
The InputDevice is created by a IResourceProvider
inside VL.IO.Midi
public class MidiInObservable : MidiObservable
{
private readonly int FDeviceID;
public MidiInObservable(int deviceID)
: base(CreateMidiInResourceProvider(deviceID))
{
FDeviceID = deviceID;
}
public bool IsOpen => ResourceProvider.ExistsInSystemWideProviderPool<int, InputDeviceMidiEvents>(FDeviceID);
static IResourceProvider<InputDeviceMidiEvents> CreateMidiInResourceProvider(int deviceID)
{
return ResourceProvider.NewPooledSystemWide(deviceID, id =>
{
var midiInDevice = new InputDevice(id, false);
return new InputDeviceMidiEvents(midiInDevice);
})
.ShareInParallel(delayDisposalInMilliseconds: 250);
}
}
The ResourceProvider returns InputDeviceMidiEvents
which it (afaik) should dispose when “no one” is using it anymore, which in turn would dispose the InputDevice
. But that doesn’t happen.
To reproduce just open the patch and then close vvvv again look for the vvvv process in the taskmanager.
Tried it with vvvv versions down to 2021.4.0.
ResourceProvider.vl (3.8 KB)