Fix crash on device start when the driver reports sample rates as a range - #1054
Merged
Merged
Conversation
Drivers that only implement getSampleRateRange() (e.g. the usdr module for Wavelet Lab xSDR) crash CubicSDR on device start with: terminating due to uncaught exception of type std::runtime_error: SoapyUSDR::setSampleRate() unable to set samplerate! Two problems in SDRDeviceInfo::getSampleRates(): - SoapySDR's deprecated-API shim expands a continuous rate range into a stepped list whose first entry is 0. The 0 survives decimation, getSampleRateNear() picks it, and the driver throws on setSampleRate(0). Filter out non-positive rates. - If a driver returns an empty rate list, the existing code calls sampleRates.back() on an empty vector (undefined behavior). Synthesize a candidate list from getSampleRateRange() instead, fall back to the range endpoints, and bail out cleanly if there is no rate information at all. Verified on a Wavelet Lab xSDR over USB: device selection previously aborted the app, now starts and streams normally.
Owner
|
Seems like a reasonable solution when the list is empty/zero/range-only; checks passed on pr test branch -- thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Selecting a device whose SoapySDR driver only implements
getSampleRateRange()(no discretelistSampleRates()) aborts CubicSDR on start:Observed with the Wavelet Lab xSDR (
usdrSoapy module, reports a continuous 1-125 MSps range), but any range-only driver is affected.Root cause
Two issues in
SDRDeviceInfo::getSampleRates():0.0. The 0 survives CubicSDR's decimation step,getSampleRateNear()selects it (it wins ties against valid rates), and the driver throws onsetSampleRate(0). The exception is never caught, so the app aborts.sampleRates.back()on an empty vector, which is undefined behavior.Fix
listSampleRates()result.getSampleRateRange()(common rates that fall within the reported ranges, falling back to the range endpoints).Existing discrete-list drivers are unaffected: their lists contain no non-positive entries and are non-empty, so both new paths are no-ops.
Testing
Verified on a Wavelet Lab xSDR over USB on macOS (arm64, SoapySDR 0.8.1): device selection previously aborted the app 100% of the time; with this change it starts, streams, and the sample-rate menu is populated with valid rates.
🤖 Generated with Claude Code