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();