bitcraze / crazyflie-clients-python

Host applications and library for Crazyflie written in Python.
Other
310 stars 474 forks source link

Lighthouse geometry estimation crashes on Mac M1 with Python 3.11 #714

Open ataffanel opened 5 months ago

ataffanel commented 5 months ago

As reported in discussions, When estimating geometry for the lighthouse system, the client crashes on Macintosh with apple silicon with Python 3.11 native. This crash has not been reproduced on other platform.

The crash happens then the geometry estimation code is run (when clicking the "estimate geometry" button. and the followind message is shown in the console: zsh: bus error cfclient

This is an extract of the debug information given by MacOS:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               Python [5746]
Path:                  /opt/homebrew/*/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python
Identifier:            org.python.python
Version:               3.11.9 (3.11.9)
Code Type:             ARM-64 (Native)
Parent Process:        zsh [2107]
Responsible:           Terminal [2105]
User ID:               501

Date/Time:             2024-06-03 11:11:59.2785 +0200
OS Version:            macOS 14.5 (23F79)
Report Version:        12
Anonymous UUID:        2ECAB03F-A8F7-1FBE-2708-A5D40012C410

Sleep/Wake UUID:       3402A3EC-29A0-4B5D-B834-AD2293C321D7

Time Awake Since Boot: 11000 seconds
Time Since Wake:       946 seconds

System Integrity Protection: enabled

Crashed Thread:        42  QThread

Exception Type:        EXC_BAD_ACCESS (SIGBUS)
Exception Codes:       KERN_PROTECTION_FAILURE at 0x000000032f18bff8
Exception Codes:       0x0000000000000002, 0x000000032f18bff8

Termination Reason:    Namespace SIGNAL, Code 10 Bus error: 10
Terminating Process:   exc handler [5746]

VM Region Info: 0x32f18bff8 is in 0x32f188000-0x32f18c000;  bytes after start: 16376  bytes before end: 7
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      VM_ALLOCATE                 32f088000-32f188000    [ 1024K] rw-/rwx SM=PRV  
--->  STACK GUARD                 32f188000-32f18c000    [   16K] ---/rwx SM=NUL  stack guard for thread 42
      Stack                       32f18c000-32f214000    [  544K] rw-/rwx SM=PRV  thread 42

(...)

Thread 42 Crashed:: QThread
0   libsystem_pthread.dylib                0x1994b1d74 ___chkstk_darwin + 60
1   libopenblas64_.0.dylib                 0x103469ce0 dgetrf_parallel + 52
2   libopenblas64_.0.dylib                 0x103311b30 dgesv_64_ + 372
3   _umath_linalg.cpython-311-darwin.so        0x10191b390 void solve<double>(char**, long const*, long const*, void*) + 936
4   _multiarray_umath.cpython-311-darwin.so        0x101b5e438 generic_wrapped_legacy_loop + 40
5   _multiarray_umath.cpython-311-darwin.so        0x101b65b40 ufunc_generic_fastcall + 15976
6   Python                                 0x100b8b200 _PyEval_EvalFrameDefault + 42016
7   Python                                 0x100b8f9d8 _PyEval_Vector + 116
8   Python                                 0x100aadcbc PyObject_Vectorcall + 76
9   _multiarray_umath.cpython-311-darwin.so        0x101a7a9a8 dispatcher_vectorcall + 628
10  Python                                 0x100b8b200 _PyEval_EvalFrameDefault + 42016
11  Python                                 0x100b8f9d8 _PyEval_Vector + 116
12  Python                                 0x100ab0594 method_vectorcall + 384
13  QtCore.abi3.so                         0x11635d924 PyQtSlot::call(_object*, _object*) const + 68
14  QtCore.abi3.so                         0x11635d7b4 PyQtSlot::invoke(void**, _object*, void*, bool) const + 292
15  QtCore.abi3.so                         0x11635e704 PyQtSlotProxy::unislot(void**) + 92
16  QtCore.abi3.so                         0x11635e674 PyQtSlotProxy::qt_metacall(QMetaObject::Call, int, void**) + 68
17  QtCore                                 0x1149ef5f4 0x114920000 + 849396
18  QtCore                                 0x114a88dbc QThread::started(QThread::QPrivateSignal) + 56
19  QtCore                                 0x114b183a0 0x114920000 + 2065312
20  libsystem_pthread.dylib                0x1994b6f94 _pthread_start + 136
21  libsystem_pthread.dylib                0x1994b1d34 thread_start + 8

Thread 42 crashed with ARM Thread State (64-bit):
    x0: 0x000000032f20c648   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000112920000
    x4: 0x0000000112948000   x5: 0x0000000000000000   x6: 0x000000032f20c7e0   x7: 0x000000032f20c800
    x8: 0x0000000000000008   x9: 0x0000000000084610  x10: 0x000000032f187fc0  x11: 0x000000032f18c000
   x12: 0x0000000000000000  x13: 0x0000000000000000  x14: 0x00000000000007fb  x15: 0x00000000e1e05853
   x16: 0x00000001994b1d38  x17: 0x00000000e2005052  x18: 0x0000000000000000  x19: 0x000000032f20c800
   x20: 0x000000032f20c7d0  x21: 0x0000000112920000  x22: 0x000000032f20c7c8  x23: 0x0000000112920000
   x24: 0x0000000112948000  x25: 0x00006000021a38d8  x26: 0x0000000000000003  x27: 0x0000000000000003
   x28: 0x0000000000000018   fp: 0x000000032f20c630   lr: 0x0000000103469ce0
    sp: 0x000000032f20c5d0   pc: 0x00000001994b1d74 cpsr: 0x80001000
   far: 0x000000032f18bff8  esr: 0x92000007 (Data Abort) byte read Translation fault

So the crash definitly seems to happen within the linear algebra module of Python.

r-bt commented 3 weeks ago

Any progress with this?

r-bt commented 3 weeks ago

I followed this guide here: https://or-levi.medium.com/python-management-on-apple-silicon-arm-x86-with-pyenv-f786cf8a48f8 and installed an x86 version of python, pip installed a new cfclient and then ran Estimate Geometry and it worked!

Bananazooka commented 3 weeks ago

Thank you! @ataffanel is currently away, but we'll notify him when he gets back.