Open KeyserSoze-ND opened 1 day ago
This smells like a double-free. For a quick fix note that closeStream
will also deactivateStream
and that dropping the reference to Device
will also closeStream
implicitly -- you should be okay to just del sdr
.
edit: actually __del__
will close
and that in turn will unmake
(as seen in the trace), streams are not implicitly closed. Strange then where unmake fails. SoapyRTLSDR's destructor has nothing but a rtlsdr_close(dev)
call.
I tried the following:
def main():
args = {'driver': 'rtlsdr'}
sdr = SoapySDR.Device(args)
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, 0, 2.048e6)
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, 0, 100e6)
stream = sdr.setupStream(SoapySDR.SOAPY_SDR_RX, SoapySDR.SOAPY_SDR_CF32)
sdr.activateStream(stream)
time.sleep(1)
#sdr.deactivateStream(stream)
sdr.closeStream(stream)
print("Stream closed")
time.sleep(1)
if __name__ == "__main__":
while True:
main()
This fails the same way.
I also tried this:
def main():
args = {'driver': 'rtlsdr'}
sdr = SoapySDR.Device(args)
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, 0, 2.048e6)
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, 0, 100e6)
stream = sdr.setupStream(SoapySDR.SOAPY_SDR_RX, SoapySDR.SOAPY_SDR_CF32)
sdr.activateStream(stream)
time.sleep(1)
del sdr
print("Stream closed")
time.sleep(1)
if __name__ == "__main__":
while True:
main()
Interestingly, this does not crash but just hangs. The python kernel stops responding. (CTRL+C does not work etc.)
I guess the first example might keep the sdr
Device around and the second tries to force a close
with an active stream, which won't work as the rtlsdr async is still running.
All around your examples are valid and what should be expected to work from a Python perspective.
There are no clues why the unmake
would fail after some tries. We likely need to try if this also appears in a similar C example and then debug the state, perhaps with gcc. I'll try to run this code on Linux and see if it can be reproduced. I hope it's not some Windows pecularity.
I can reproduce this in Linux, seems to be particular to Windows or your setup. Do you have WSL? Can you reproduce this in WSL? Are you up to trying the same example in C? That would make out or exclude Python as the culprit.
I do not have WSL but VSCode has an extension for it so I will try to reproduce this in WSL. I never used this library in C but I can also try this with C while I am at it.
I'm encountering a
Windows fatal exception: access violation error
when using SoapyRTLSDR on Windows 11 Home 64-bit. The crash occurs when trying to interact with the RTL-SDR device (NooElec R820T2 SDR & DVB-T) using SoapySDR, and it seems to be a bug in the SoapyRTLSDR implementation on Windows.The crash happens silently, but after adding the Python
faulthandler
library, I was able to trace the exact point of failure.Environment:
SoapySDRUtil output:
The following python script can be used to reproduce the error:
Expected behaviour: The program should run without crashing, and the SDR device should be properly deactivated and closed at each iteration.
Actual behaviour: The program crashes with a "Windows fatal exception: access violation error" in the
SoapySDR.py
library when closing the stream and cleaning up the SDR device. Here is the error traceback captured usingfaulthandler
:Additional Information:
Possible Cause:
unmake
.Please let me know if you need further information, and I can provide more details.