diff --git a/Arduino/PS_BLE_ShotDetection/PS_BLE_ShotDetection.ino b/Arduino/PS_BLE_ShotDetection/PS_BLE_ShotDetection.ino index 943ac46..1102d60 100644 --- a/Arduino/PS_BLE_ShotDetection/PS_BLE_ShotDetection.ino +++ b/Arduino/PS_BLE_ShotDetection/PS_BLE_ShotDetection.ino @@ -574,9 +574,10 @@ void loop() { sendDebugData(accelMag, gyroMag, audioLevel); printDebugSerial(accelMag, gyroMag, audioLevel); - // ─── IMU BLE 10 Hz (debug uniquement) ─── - // En production (debugMode OFF), pas d'envoi IMU → charge BLE réduite pour Unreal - if (debugMode != DEBUG_OFF && now-lastSend>=100) { + // ─── IMU BLE 10 Hz ─── + // TODO_TEST : envoi IMU toujours actif pour test (Pico Motion Tracker en production) + // REMETTRE : if (debugMode != DEBUG_OFF && now-lastSend>=100) { + if (now-lastSend>=100) { lastSend=now; float dt=(now-lastUpdate)/1000.0f; lastUpdate=now; roll+=gx*dt; pitch+=gy*dt; yaw+=gz*dt; diff --git a/Unreal/PS_BLE_Tracker.uproject b/Unreal/PS_BLE_Tracker.uproject index d680761..1997abe 100644 --- a/Unreal/PS_BLE_Tracker.uproject +++ b/Unreal/PS_BLE_Tracker.uproject @@ -18,6 +18,10 @@ "Editor" ] }, + { + "Name": "WinBluetoothLE", + "Enabled": false + }, { "Name": "PS_Win_BLE", "Enabled": true diff --git a/Unreal/Plugins/PS_Win_BLE/Source/PS_Win_BLE/Private/PS_BLEModule.cpp b/Unreal/Plugins/PS_Win_BLE/Source/PS_Win_BLE/Private/PS_BLEModule.cpp index c5bab2b..8ee2953 100644 --- a/Unreal/Plugins/PS_Win_BLE/Source/PS_Win_BLE/Private/PS_BLEModule.cpp +++ b/Unreal/Plugins/PS_Win_BLE/Source/PS_Win_BLE/Private/PS_BLEModule.cpp @@ -5,6 +5,7 @@ #include "PS_BLEDevice.h" #include "Async/Async.h" #include "Misc/MessageDialog.h" +#include "Misc/CoreDelegates.h" #include "Modules/ModuleManager.h" // ─── WinRT includes (Windows only) ─────────────────────────────────────────── @@ -92,6 +93,19 @@ void UPS_BLE_Module::StartupModule() LocalBLEManager = NewObject(); LocalBLEManager->AddToRoot(); // prevent GC LocalBLEManager->AttachModule(this); + + // Cleanup UObjects before Unreal's UObject array is destroyed. + // ShutdownModule() is called too late (UObjectArray already partially torn down) + // → we do RemoveFromRoot here, during pre-exit, which is still safe. + FCoreDelegates::OnPreExit.AddLambda([this]() + { + if (LocalBLEManager) + { + LocalBLEManager->DisconnectAll(); + LocalBLEManager->RemoveFromRoot(); + LocalBLEManager = nullptr; + } + }); #else FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("PS_Win_BLE_Platform", "PS_Win_BLE: BLE is only supported on Windows 64-bit.")); @@ -103,12 +117,10 @@ void UPS_BLE_Module::ShutdownModule() #if PLATFORM_WINDOWS ScannerCleanup(); - if (LocalBLEManager) - { - LocalBLEManager->DisconnectAll(); - LocalBLEManager->RemoveFromRoot(); - LocalBLEManager = nullptr; - } + // NOTE: LocalBLEManager cleanup (DisconnectAll + RemoveFromRoot) is handled + // in the OnPreExit delegate registered in StartupModule, because ShutdownModule + // is called after the UObject array has started to be destroyed (causes Index >= 0 crash). + LocalBLEManager = nullptr; if (bWinRTCoInitialized) {