matrix-io / matrix-creator-hal

Hardware Abstraction Layer for MATRIX Creator & MATRIX Voice
https://matrix-io.github.io/matrix-documentation/matrix-hal/overview/
GNU General Public License v3.0
70 stars 50 forks source link

MicrophoneArray segmentation fault #97

Open glhahn opened 4 years ago

glhahn commented 4 years ago

Has anyone else run into issues with the mic_demo_direct demo? I've encountered segmentation faults when modifying the demo (such as adding variables, etc.) that I haven't been able to explain.

So I enabled debug builds in cmake (setting CMAKE_BUILD_TYPE to Debug) for mic_demo_direct and the matrix_creator_hal library, and then I ran gdb to see where the segmentation fault was occurring. It took me to line 40 of demos/mic_demo_direct.cpp. Stepping through, the MicrophoneArray is initialized with enable_beamforming = true and proceeds on to the MicrophoneArray::CalculateDelays() method.

In CalculateDelays() (cpp/driver/microphonearray.cpp), it goes to line 122. The segfault happens here, where the bus pointer (cpp/driver/matrixdriver.h:32) references an invalid address. If I run gdb with the unmodified demo it will continue to run, but with bus referencing an uninitialized MatrixIOBus.

Basically, it seems the root of the issue is that if the MicrophoneArray constructor is run with beamforming enabled then MicrophoneArray ends up trying to call MatrixIOBus::MatrixLeds() using an unset bus pointer. This happens before the bus can be initialized with MicrophoneArray::Setup().

fpgasdr commented 3 years ago

Hi, I have the same error with the direction_of_arrival_demo_direct. thanks for the info, i will try to debug it.