From 4691ce5ecf4c7014ff2bd9b03ec7045f0d075067 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 8 Nov 2018 16:07:45 -0600 Subject: [PATCH] If commands are buffered and not sent when the device is disconnected, call any completion callbacks. This is to guarantee that completion callbacks are always called, so if any resource collection happens in them it'll always happen. --- sdk/Windows/SMXDeviceConnection.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sdk/Windows/SMXDeviceConnection.cpp b/sdk/Windows/SMXDeviceConnection.cpp index 5f9b5dc..5f47b1a 100644 --- a/sdk/Windows/SMXDeviceConnection.cpp +++ b/sdk/Windows/SMXDeviceConnection.cpp @@ -56,6 +56,19 @@ void SMX::SMXDeviceConnection::Close() if(m_hDevice) CancelIo(m_hDevice->value()); + // If we're being closed while a command was in progress, call its completion + // callback, so it's guaranteed to always be called. + if(m_pCurrentCommand && m_pCurrentCommand->m_pComplete) + m_pCurrentCommand->m_pComplete(); + + // If any commands were queued with completion callbacks, call their completion + // callbacks. + for(auto &pendingCommand: m_aPendingCommands) + { + if(pendingCommand->m_pComplete) + pendingCommand->m_pComplete(); + } + m_hDevice.reset(); m_sReadBuffers.clear(); m_aPendingCommands.clear();