PS_Win_BLE: fix crash on disconnect - use TWeakObjectPtr in all async dispatches
All Dispatch* functions now capture UPS_BLE_Device via TWeakObjectPtr instead of a raw pointer, preventing an access violation when the UObject is garbage collected before the GameThread lambda executes (EXCEPTION_ACCESS_VIOLATION @ 0x60). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
10ca1e19c7
commit
aa8df59af2
@ -664,10 +664,12 @@ void UPS_BLE_Module::DispatchDeviceConnected(UPS_BLE_Device* Dev)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AsyncTask(ENamedThreads::GameThread, [Dev]()
|
TWeakObjectPtr<UPS_BLE_Device> WeakDev(Dev);
|
||||||
|
AsyncTask(ENamedThreads::GameThread, [WeakDev]()
|
||||||
{
|
{
|
||||||
Dev->RefToManager->JustConnectedDevice(Dev);
|
if (!WeakDev.IsValid()) return;
|
||||||
Dev->OnConnect.Broadcast(Dev, Dev->ActiveServices);
|
WeakDev->RefToManager->JustConnectedDevice(WeakDev.Get());
|
||||||
|
WeakDev->OnConnect.Broadcast(WeakDev.Get(), WeakDev->ActiveServices);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -682,10 +684,12 @@ void UPS_BLE_Module::DispatchDeviceDisconnected(UPS_BLE_Device* Dev)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AsyncTask(ENamedThreads::GameThread, [Dev]()
|
TWeakObjectPtr<UPS_BLE_Device> WeakDev(Dev);
|
||||||
|
AsyncTask(ENamedThreads::GameThread, [WeakDev]()
|
||||||
{
|
{
|
||||||
Dev->RefToManager->JustDisconnectedDevice(Dev);
|
if (!WeakDev.IsValid()) return;
|
||||||
Dev->OnDisconnect.Broadcast(Dev);
|
WeakDev->RefToManager->JustDisconnectedDevice(WeakDev.Get());
|
||||||
|
WeakDev->OnDisconnect.Broadcast(WeakDev.Get());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -700,10 +704,12 @@ void UPS_BLE_Module::DispatchServicesDiscovered(UPS_BLE_Device* Dev)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AsyncTask(ENamedThreads::GameThread, [Dev]()
|
TWeakObjectPtr<UPS_BLE_Device> WeakDev(Dev);
|
||||||
|
AsyncTask(ENamedThreads::GameThread, [WeakDev]()
|
||||||
{
|
{
|
||||||
Dev->RefToManager->JustDiscoveredServices(Dev);
|
if (!WeakDev.IsValid()) return;
|
||||||
Dev->OnServicesDiscovered.Broadcast(Dev, Dev->ActiveServices);
|
WeakDev->RefToManager->JustDiscoveredServices(WeakDev.Get());
|
||||||
|
WeakDev->OnServicesDiscovered.Broadcast(WeakDev.Get(), WeakDev->ActiveServices);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -719,11 +725,13 @@ void UPS_BLE_Module::DispatchRead(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS_G
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AsyncTask(ENamedThreads::GameThread, [Dev, SI, CI, Status, Data]()
|
TWeakObjectPtr<UPS_BLE_Device> WeakDev(Dev);
|
||||||
|
AsyncTask(ENamedThreads::GameThread, [WeakDev, SI, CI, Status, Data]()
|
||||||
{
|
{
|
||||||
if (SI < Dev->ActiveServices.Num() && CI < Dev->ActiveServices[SI].Characteristics.Num())
|
if (!WeakDev.IsValid()) return;
|
||||||
Dev->OnRead.Broadcast(Status, Dev, Dev->ActiveServices[SI].ServiceUUID,
|
if (SI < WeakDev->ActiveServices.Num() && CI < WeakDev->ActiveServices[SI].Characteristics.Num())
|
||||||
Dev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID, Data);
|
WeakDev->OnRead.Broadcast(Status, WeakDev.Get(), WeakDev->ActiveServices[SI].ServiceUUID,
|
||||||
|
WeakDev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID, Data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -739,11 +747,13 @@ void UPS_BLE_Module::DispatchNotify(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AsyncTask(ENamedThreads::GameThread, [Dev, SI, CI, Status, Data]()
|
TWeakObjectPtr<UPS_BLE_Device> WeakDev(Dev);
|
||||||
|
AsyncTask(ENamedThreads::GameThread, [WeakDev, SI, CI, Status, Data]()
|
||||||
{
|
{
|
||||||
if (SI < Dev->ActiveServices.Num() && CI < Dev->ActiveServices[SI].Characteristics.Num())
|
if (!WeakDev.IsValid()) return;
|
||||||
Dev->OnNotify.Broadcast(Status, Dev, Dev->ActiveServices[SI].ServiceUUID,
|
if (SI < WeakDev->ActiveServices.Num() && CI < WeakDev->ActiveServices[SI].Characteristics.Num())
|
||||||
Dev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID, Data);
|
WeakDev->OnNotify.Broadcast(Status, WeakDev.Get(), WeakDev->ActiveServices[SI].ServiceUUID,
|
||||||
|
WeakDev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID, Data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -751,11 +761,13 @@ void UPS_BLE_Module::DispatchNotify(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS
|
|||||||
void UPS_BLE_Module::DispatchWrite(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS_GATTStatus Status)
|
void UPS_BLE_Module::DispatchWrite(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS_GATTStatus Status)
|
||||||
{
|
{
|
||||||
if (!Dev) return;
|
if (!Dev) return;
|
||||||
auto Fire = [Dev, SI, CI, Status]()
|
TWeakObjectPtr<UPS_BLE_Device> WeakDev(Dev);
|
||||||
|
auto Fire = [WeakDev, SI, CI, Status]()
|
||||||
{
|
{
|
||||||
if (SI < Dev->ActiveServices.Num() && CI < Dev->ActiveServices[SI].Characteristics.Num())
|
if (!WeakDev.IsValid()) return;
|
||||||
Dev->OnWrite.Broadcast(Status, Dev, Dev->ActiveServices[SI].ServiceUUID,
|
if (SI < WeakDev->ActiveServices.Num() && CI < WeakDev->ActiveServices[SI].Characteristics.Num())
|
||||||
Dev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID);
|
WeakDev->OnWrite.Broadcast(Status, WeakDev.Get(), WeakDev->ActiveServices[SI].ServiceUUID,
|
||||||
|
WeakDev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID);
|
||||||
};
|
};
|
||||||
if (IsInGameThread()) Fire();
|
if (IsInGameThread()) Fire();
|
||||||
else AsyncTask(ENamedThreads::GameThread, Fire);
|
else AsyncTask(ENamedThreads::GameThread, Fire);
|
||||||
@ -764,13 +776,15 @@ void UPS_BLE_Module::DispatchWrite(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS_
|
|||||||
void UPS_BLE_Module::DispatchSubscribe(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS_GATTStatus Status)
|
void UPS_BLE_Module::DispatchSubscribe(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS_GATTStatus Status)
|
||||||
{
|
{
|
||||||
if (!Dev) return;
|
if (!Dev) return;
|
||||||
auto Fire = [Dev, SI, CI, Status]()
|
TWeakObjectPtr<UPS_BLE_Device> WeakDev(Dev);
|
||||||
|
auto Fire = [WeakDev, SI, CI, Status]()
|
||||||
{
|
{
|
||||||
if (SI < Dev->ActiveServices.Num() && CI < Dev->ActiveServices[SI].Characteristics.Num())
|
if (!WeakDev.IsValid()) return;
|
||||||
|
if (SI < WeakDev->ActiveServices.Num() && CI < WeakDev->ActiveServices[SI].Characteristics.Num())
|
||||||
{
|
{
|
||||||
Dev->ActiveServices[SI].Characteristics[CI].subscribed = true;
|
WeakDev->ActiveServices[SI].Characteristics[CI].subscribed = true;
|
||||||
Dev->OnSubscribe.Broadcast(Status, Dev, Dev->ActiveServices[SI].ServiceUUID,
|
WeakDev->OnSubscribe.Broadcast(Status, WeakDev.Get(), WeakDev->ActiveServices[SI].ServiceUUID,
|
||||||
Dev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID);
|
WeakDev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (IsInGameThread()) Fire();
|
if (IsInGameThread()) Fire();
|
||||||
@ -780,13 +794,15 @@ void UPS_BLE_Module::DispatchSubscribe(UPS_BLE_Device* Dev, uint8 SI, uint8 CI,
|
|||||||
void UPS_BLE_Module::DispatchUnsubscribe(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS_GATTStatus Status)
|
void UPS_BLE_Module::DispatchUnsubscribe(UPS_BLE_Device* Dev, uint8 SI, uint8 CI, EPS_GATTStatus Status)
|
||||||
{
|
{
|
||||||
if (!Dev) return;
|
if (!Dev) return;
|
||||||
auto Fire = [Dev, SI, CI, Status]()
|
TWeakObjectPtr<UPS_BLE_Device> WeakDev(Dev);
|
||||||
|
auto Fire = [WeakDev, SI, CI, Status]()
|
||||||
{
|
{
|
||||||
if (SI < Dev->ActiveServices.Num() && CI < Dev->ActiveServices[SI].Characteristics.Num())
|
if (!WeakDev.IsValid()) return;
|
||||||
|
if (SI < WeakDev->ActiveServices.Num() && CI < WeakDev->ActiveServices[SI].Characteristics.Num())
|
||||||
{
|
{
|
||||||
Dev->ActiveServices[SI].Characteristics[CI].subscribed = false;
|
WeakDev->ActiveServices[SI].Characteristics[CI].subscribed = false;
|
||||||
Dev->OnUnsubscribe.Broadcast(Status, Dev, Dev->ActiveServices[SI].ServiceUUID,
|
WeakDev->OnUnsubscribe.Broadcast(Status, WeakDev.Get(), WeakDev->ActiveServices[SI].ServiceUUID,
|
||||||
Dev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID);
|
WeakDev->ActiveServices[SI].Characteristics[CI].CharacteristicUUID);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (IsInGameThread()) Fire();
|
if (IsInGameThread()) Fire();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user