Skip to content

Access Violation in SoapyRTLSDR on Windows 11 (PothosSDR installation) for Consecutive Runs #76

@hnbicer

Description

@hnbicer

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:

  • Operating System: Windows 11 Home 64-bit
  • Installer Used: PothosSDR-2021-07-25-vc16-x64.exe
  • SDR Device: NooElec R820T2 SDR & DVB-T NESDR Mini 2

SoapySDRUtil output:

C:\PothosSDR>SoapySDRUtil --info
######################################################
##     Soapy SDR -- the SDR abstraction library     ##
######################################################

Lib Version: v0.8.1-PothosSDR-2021.07.25-vc16-x64
API Version: v0.8.0
ABI Version: v0.8
Install root: C:\PothosSDR
Search path:  C:\PothosSDR/lib/SoapySDR/modules0.8
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/airspyhfSupport.dll (0.2.0-d682533)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/airspySupport.dll   (0.2.0-411f73e)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/audioSupport.dll    (0.1.1-91080cb)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/bladeRFSupport.dll  (0.4.1-70505a5)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/HackRFSupport.dll   (0.3.3-8d2e7be)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/IrisSupport.dll     (2020.02.0.1-f100723)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/LMS7Support.dll     (20.10.0-a45e482d)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/miriSupport.dll     (0.2.6-585c012)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/netSDRSupport.dll   (0.1.0-51516db)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/osmosdrSupport.dll  (0.2.6-585c012)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/RedPitaya.dll       (0.1.1-3d576f8)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/remoteSupport.dll   (0.6.0-c09b2f1)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/rtlsdrSupport.dll   (0.3.2-53ee8f4)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/sdrPlaySupport.dll  (0.3.0-206b241)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/uhdSupport.dll      (0.4.1-9a738c3)
Module found: C:\PothosSDR/lib/SoapySDR/modules0.8/volkConverters.dll[WARNING] SoapyVOLKConverters: no VOLK config file found. Run volk_profile for best performance.
  (0.1.0-62ac7f5)
Available factories... airspy, airspyhf, audio, bladerf, hackrf, iris, lime, miri, netsdr, osmosdr, redpitaya, remote, rtlsdr, sdrplay, uhd
Available converters...
 -  CF32 -> [CF32, CF64, CS16, CS32, CS8, CU16, CU8]
 -  CF64 -> [CF32, CS16, CS32, CS8]
 -  CS16 -> [CF32, CF64, CS16, CS8, CU16, CU8]
 -  CS32 -> [CF32, CF64, CS32]
 -   CS8 -> [CF32, CF64, CS16, CS8, CU16, CU8]
 -  CU16 -> [CF32, CS16, CS8]
 -   CU8 -> [CF32, CS16, CS8]
 -   F32 -> [F32, F64, S16, S32, S8, U16, U8]
 -   F64 -> [F32, S16, S32, S8]
 -   S16 -> [F32, F64, S16, S8, U16, U8]
 -   S32 -> [F32, F64, S32]
 -    S8 -> [F32, F64, S16, S8, U16, U8]
 -   U16 -> [F32, S16, S8]
 -    U8 -> [F32, S16, S8]

The following python script can be used to reproduce the error:

import os
import ctypes
os.add_dll_directory(r'C:\PothosSDR\bin') # 
ctypes.windll.LoadLibrary(r'C:\PothosSDR\\bin\rtlsdr.dll') # 
import SoapySDR
import time
import faulthandler
faulthandler.enable()

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

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 using faulthandler:

[WARNING] SoapyVOLKConverters: no VOLK config file found. Run volk_profile for best performance.
Found Rafael Micro R820T/2 tuner
[INFO] Opening Generic RTL2832U OEM :: df47a2b4edae...
Found Rafael Micro R820T/2 tuner
[INFO] Using format CF32.
Allocating 15 (non-zero-copy) user-space buffers
Stream closed
[INFO] Opening Generic RTL2832U OEM :: df47a2b4edae...
Found Rafael Micro R820T/2 tuner
[INFO] Using format CF32.
Allocating 15 (non-zero-copy) user-space buffers
Stream closed
[INFO] Opening Generic RTL2832U OEM :: df47a2b4edae...
Found Rafael Micro R820T/2 tuner
[INFO] Using format CF32.
Allocating 15 (non-zero-copy) user-space buffers
Stream closed
[INFO] Opening Generic RTL2832U OEM :: df47a2b4edae...
Found Rafael Micro R820T/2 tuner
[INFO] Using format CF32.
Allocating 15 (non-zero-copy) user-space buffers
Stream closed
[INFO] Opening Generic RTL2832U OEM :: df47a2b4edae...
Found Rafael Micro R820T/2 tuner
[INFO] Using format CF32.
Allocating 15 (non-zero-copy) user-space buffers
Stream closed
Windows fatal exception: access violation

Current thread 0x00000a0c (most recent call first):
  File "C:\Users\avioh\anaconda3\envs\rtlsdr-test-2\lib\site-packages\SoapySDR.py", line 1484 in unmake
  File "C:\Users\avioh\anaconda3\envs\rtlsdr-test-2\lib\site-packages\SoapySDR.py", line 1822 in close
  File "C:\Users\avioh\anaconda3\envs\rtlsdr-test-2\lib\site-packages\SoapySDR.py", line 1825 in __del__
  File "c:\xx\simple_test.py", line 25 in <module>

Additional Information:

  • The issue seems specific to the Windows version of SoapyRTLSDR, as the same code works on Linux without issue.
  • The crash occurs during the cleanup process, particularly in the unmake and close functions of the SoapySDR Python bindings.
  • Adding delays or making the cleanup process more explicit (with deactivateStream and closeStream) does not resolve the crash.

Possible Cause:

  • Possibly related to resource cleanup since thread dies at unmake.

Please let me know if you need further information, and I can provide more details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions