Prevent badly initialized device from crashing

This commit is contained in:
rodolpheh 2023-12-05 22:46:16 +00:00
parent 824f9f1d7f
commit 533e4bb193
2 changed files with 11 additions and 7 deletions

View File

@ -15,8 +15,8 @@ using namespace godot;
UltraleapDevice::~UltraleapDevice() {
UtilityFunctions::print("Destroying device");
if (*connection == NULL) {
printf("Connection seems to be already destroyed\n");
if (connection == NULL || *connection == NULL) {
printf("Connection is invalid or destroyed\n");
return;
}
unsubscribe();
@ -218,7 +218,8 @@ void UltraleapDevice::close() {
}
void UltraleapDevice::on_frame_received(const LEAP_TRACKING_EVENT* frame) {
Ref<UltraleapFrame> new_frame = Ref<UltraleapFrame>(memnew(UltraleapFrame));
Ref<UltraleapFrame> new_frame;
new_frame.instantiate();
UltraleapFrame::fill_frame_data(new_frame, frame, rigging_transform);
frame_mutex.lock();
last_frame_ref = new_frame;
@ -226,8 +227,10 @@ void UltraleapDevice::on_frame_received(const LEAP_TRACKING_EVENT* frame) {
}
void UltraleapDevice::on_image_received(const LEAP_IMAGE* image) {
Ref<UltraleapImage> new_left_image = memnew(UltraleapImage);
Ref<UltraleapImage> new_right_image = memnew(UltraleapImage);
Ref<UltraleapImage> new_left_image;
Ref<UltraleapImage> new_right_image;
new_left_image.instantiate();
new_right_image.instantiate();
UltraleapImage::fill_images_data(new_left_image, new_right_image, image);
image_mutex.lock();
left_image_ref = new_left_image;
@ -269,7 +272,8 @@ Ref<UltraleapFrame> UltraleapDevice::get_interpolated_frame(int64_t time) {
//Get the frame
result = LeapInterpolateFrameEx(*connection, device, time, interpolatedFrame, targetFrameSize);
if (result == eLeapRS_Success) {
Ref<UltraleapFrame> new_frame = memnew(UltraleapFrame);
Ref<UltraleapFrame> new_frame;
new_frame.instantiate();
UltraleapFrame::fill_frame_data(new_frame, interpolatedFrame, rigging_transform);
return new_frame;
}

View File

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