Fix devices trying to use connection handle on destroy

This commit is contained in:
rodolpheh 2023-12-05 18:58:53 +00:00
parent 37c936d961
commit 6eec3f4b66
3 changed files with 11 additions and 7 deletions

View File

@ -15,6 +15,10 @@ using namespace godot;
UltraleapDevice::~UltraleapDevice() {
UtilityFunctions::print("Destroying device");
if (*connection == NULL) {
printf("Connection seems to be already destroyed\n");
return;
}
unsubscribe();
close();
}
@ -146,7 +150,7 @@ void UltraleapDevice::set_tracking_mode(UltraleapTypes::TrackingMode value) {
else {
UtilityFunctions::print("Invalid value for tracking mode");
}
LeapSetPolicyFlagsEx(connection, device, set_flag, clear_flag);
LeapSetPolicyFlagsEx(*connection, device, set_flag, clear_flag);
}
}
@ -159,7 +163,7 @@ void UltraleapDevice::subscribe() {
UtilityFunctions::print("Device already subscribed to");
return;
}
eLeapRS result = LeapSubscribeEvents(connection, device);
eLeapRS result = LeapSubscribeEvents(*connection, device);
if (result != eLeapRS_Success) {
UtilityFunctions::print(UltraleapTypes::ultraleap_result_to_string(result));
return;
@ -172,7 +176,7 @@ void UltraleapDevice::unsubscribe() {
UtilityFunctions::print("Device not subscribed to");
return;
}
eLeapRS result = LeapUnsubscribeEvents(connection, device);
eLeapRS result = LeapUnsubscribeEvents(*connection, device);
if (result != eLeapRS_Success) {
UtilityFunctions::print(UltraleapTypes::ultraleap_result_to_string(result));
return;
@ -258,12 +262,12 @@ Ref<UltraleapFrame> UltraleapDevice::get_interpolated_frame(int64_t time) {
uint64_t targetFrameSize = 0;
//Get the buffer size needed to hold the tracking data
eLeapRS result = LeapGetFrameSizeEx(connection, device, time, &targetFrameSize);
eLeapRS result = LeapGetFrameSizeEx(*connection, device, time, &targetFrameSize);
if (result == eLeapRS_Success) {
//Allocate enough memory
LEAP_TRACKING_EVENT* interpolatedFrame = (LEAP_TRACKING_EVENT*)malloc((size_t)targetFrameSize);
//Get the frame
result = LeapInterpolateFrameEx(connection, device, time, interpolatedFrame, targetFrameSize);
result = LeapInterpolateFrameEx(*connection, device, time, interpolatedFrame, targetFrameSize);
if (result == eLeapRS_Success) {
Ref<UltraleapFrame> new_frame = memnew(UltraleapFrame);
UltraleapFrame::fill_frame_data(new_frame, interpolatedFrame, rigging_transform);

View File

@ -64,7 +64,7 @@ public:
LEAP_DEVICE_REF device_ref;
LEAP_DEVICE device;
LEAP_CONNECTION connection;
LEAP_CONNECTION* connection;
LEAP_CLOCK_REBASER rebaser;
void tracking_mode_changed(UltraleapTypes::TrackingMode value);

View File

@ -754,7 +754,7 @@ Ref<UltraleapDevice> UltraleapHandTracking::create_device(LEAP_DEVICE_REF ref) {
dev->id = ref.id;
dev->device_ref = ref;
dev->connection = connectionHandle;
dev->connection = &connectionHandle;
UtilityFunctions::print("Created device with ID: ", ref.id, ", type: ", deviceInfo.pid, ", serial number: ", deviceInfo.serial);