diff --git a/stimBuffApis/livoxGen1/livoxGen1.cpp b/stimBuffApis/livoxGen1/livoxGen1.cpp index 45cee8a..3cd73a2 100644 --- a/stimBuffApis/livoxGen1/livoxGen1.cpp +++ b/stimBuffApis/livoxGen1/livoxGen1.cpp @@ -511,16 +511,16 @@ livoxGen1_detachDeviceCReq( // Case 2: StimBuffer exists - proceed with detach auto requestComponentThread = stimProducer->device->componentThread; - /** FIXME: - * We always disable Livox pcloud sampling here, even when other - * StimBuffers on this PcloudStimulusProducer will remain attached. - * That leaves surviving qualae without a device stream until something - * re-enables pcloud (e.g. a later attach). PcloudStimulusProducer:: - * destroyAttachedStimulusBuffer() stop()/start() only pauses the SMO - * io_uring/OpenCL frame pipeline for buffer-list mutation; it does not - * turn Livox sampling back on. Only call disable when detaching the - * last buffer, or re-enable after a partial detach when buffers remain. - */ + // Remove StimBuffer from collection if it exists + stimProducer->destroyAttachedStimulusBuffer(stimBuffer); + + // Check if StimProducer has other buffers + if (!stimProducer->attachedStimulusBuffers.empty()) { + // Other buffers exist - just remove this buffer, done + co_return StimBuffDeviceOpResult{true, desc}; + } + + // Last buffer on producer: disable pcloud before tearing down device // Disable point cloud data first const bool disabled = co_await coAwaitDisablePcloudData( requestComponentThread, stimProducer->device); @@ -540,25 +540,6 @@ livoxGen1_detachDeviceCReq( requestComponentThread->getIoService(), boost::posix_time::milliseconds(LIVOX_GEN1_DEVICE_COMMAND_DELAY_MS)); - // Callback for the delayed destroyDeviceReq - // Remove StimBuffer from collection if it exists - if (!stimBuffer) - { - throw std::runtime_error(std::string(__func__) - + ": stimBuffer (API: " + desc->stimBuffApi + ") " - + "is missing in detachDeviceReq1_delayed " - + "for device " + desc->deviceSelector); - } - - // Get the producer from the buffer's parent - stimProducer->destroyAttachedStimulusBuffer(stimBuffer); - - // Check if StimProducer has other buffers - if (!stimProducer->attachedStimulusBuffers.empty()) { - // Other buffers exist - just remove this buffer, done - co_return StimBuffDeviceOpResult{true, desc}; - } - // No other buffers - stop and remove StimProducer stimProducer->stop(); // Remove stimulus producer from collection before destroying device