Try to improve stability in editor
The more I made changes, the more it crashed. Got it to a point where it doesn't crash when starting the editor, but it will crash when exciting.
This commit is contained in:
parent
15ff0fff2e
commit
8b932e3a3c
|
@ -24,7 +24,8 @@ func _ready():
|
|||
func _physics_process(_delta):
|
||||
if Time.get_unix_time_from_system() - latest_update > 0.5:
|
||||
var frame : UltraleapFrame = tracking.get_last_frame()
|
||||
$Footer/TrackingFramerate.text = "Tracking Frame Rate: " + str(ceil(frame.framerate))
|
||||
if frame != null:
|
||||
$Footer/TrackingFramerate.text = "Tracking Frame Rate: " + str(ceil(frame.framerate))
|
||||
latest_update = Time.get_unix_time_from_system()
|
||||
|
||||
|
||||
|
|
|
@ -150,6 +150,7 @@ void UltraleapDevice::open() {
|
|||
|
||||
void UltraleapDevice::close() {
|
||||
LeapCloseDevice(device);
|
||||
LeapDestroyClockRebaser(rebaser);
|
||||
}
|
||||
|
||||
void UltraleapDevice::on_frame_received(const LEAP_TRACKING_EVENT* frame) {
|
||||
|
|
|
@ -192,8 +192,10 @@ void UltraleapDeviceNode::set_tracker(NodePath value) {
|
|||
|
||||
void UltraleapDeviceNode::_notification(int p_what) {
|
||||
if (p_what == Node::NOTIFICATION_READY) {
|
||||
UltraleapHandTracking* tracking = Object::cast_to<UltraleapHandTracking>(get_node_or_null(tracker));
|
||||
if (tracking != NULL) {
|
||||
Node *tracking_node = get_node_or_null(tracker);
|
||||
if (tracking_node != NULL) {
|
||||
UltraleapHandTracking* tracking = Object::cast_to<UltraleapHandTracking>(tracking_node);
|
||||
|
||||
// Connect to tracking signals
|
||||
tracking->connect("device_added", Callable((Object*)this, "device_added"));
|
||||
tracking->connect("device_removed", Callable((Object*)this, "device_removed"));
|
||||
|
|
|
@ -89,11 +89,11 @@ void UltraleapFrame::fill_frame_data(Ref<UltraleapFrame> ul_frame, const LEAP_TR
|
|||
for (size_t i = 0; i < frame->nHands; i++)
|
||||
{
|
||||
if (frame->pHands[i].type == eLeapHandType_Left) {
|
||||
UltraleapHand::fill_hand_data(ul_frame->left_hand, &frame->pHands[i]);
|
||||
UltraleapHand::fill_hand_data(ul_frame->left_hand_ref, &frame->pHands[i]);
|
||||
ul_frame->is_left_hand_visible = true;
|
||||
}
|
||||
else {
|
||||
UltraleapHand::fill_hand_data(ul_frame->right_hand, &frame->pHands[i]);
|
||||
UltraleapHand::fill_hand_data(ul_frame->right_hand_ref, &frame->pHands[i]);
|
||||
ul_frame->is_right_hand_visible = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,6 @@ class UltraleapFrame : public Resource {
|
|||
public:
|
||||
uint32_t id;
|
||||
|
||||
UltraleapHand* left_hand = memnew(UltraleapHand);
|
||||
UltraleapHand* right_hand = memnew(UltraleapHand);
|
||||
|
||||
bool is_left_hand_visible = false;
|
||||
bool is_right_hand_visible = false;
|
||||
|
||||
|
@ -49,8 +46,8 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<UltraleapHand> left_hand_ref = Ref<UltraleapHand>(left_hand);
|
||||
Ref<UltraleapHand> right_hand_ref = Ref<UltraleapHand>(right_hand);
|
||||
Ref<UltraleapHand> left_hand_ref = Ref<UltraleapHand>(memnew(UltraleapHand));
|
||||
Ref<UltraleapHand> right_hand_ref = Ref<UltraleapHand>(memnew(UltraleapHand));
|
||||
};
|
||||
|
||||
#endif
|
|
@ -223,7 +223,7 @@ void UltraleapHand::_bind_methods() {
|
|||
);
|
||||
};
|
||||
|
||||
void UltraleapHand::fill_hand_data(UltraleapHand* ul_hand, LEAP_HAND* hand) {
|
||||
void UltraleapHand::fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand) {
|
||||
ul_hand->type = hand->type == eLeapHandType_Left ? UltraleapTypes::Chirality::Left : UltraleapTypes::Chirality::Right;
|
||||
ul_hand->confidence = hand->confidence;
|
||||
ul_hand->visible_time = hand->visible_time;
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
}
|
||||
void set_digits(Array digits) { digits_array = digits; }
|
||||
|
||||
static void fill_hand_data(UltraleapHand* ul_hand, LEAP_HAND* hand);
|
||||
static void fill_hand_data(Ref<UltraleapHand> ul_hand, LEAP_HAND* hand);
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
|
|
|
@ -25,10 +25,26 @@
|
|||
|
||||
using namespace godot;
|
||||
|
||||
UltraleapHandTracking::UltraleapHandTracking() {
|
||||
UtilityFunctions::print("Initializing UltraleapHandTracking");
|
||||
|
||||
#if ANDROID_ENABLED
|
||||
// Get and store the binder
|
||||
if (Engine::get_singleton()->has_singleton("UltraleapBinder")) {
|
||||
binder = Engine::get_singleton()->get_singleton("UltraleapBinder");
|
||||
}
|
||||
#endif
|
||||
|
||||
// For now we will also start automatically if we're in the editor, so that we can have data for tool scripts
|
||||
if (autostart || Engine::get_singleton()->is_editor_hint()) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
UltraleapHandTracking::~UltraleapHandTracking() {
|
||||
UtilityFunctions::print("Destroying UltraleapHandTracking");
|
||||
|
||||
if (is_running) {
|
||||
if (is_running || messageLoop.joinable()) {
|
||||
UtilityFunctions::print("Stopping the tracking thread");
|
||||
keep_running = false;
|
||||
messageLoop.join();
|
||||
|
@ -39,6 +55,8 @@ UltraleapHandTracking::~UltraleapHandTracking() {
|
|||
#if ANDROID_ENABLED
|
||||
binder = NULL;
|
||||
#endif
|
||||
|
||||
UtilityFunctions::print("UltraleapHandTracking destroyed");
|
||||
}
|
||||
|
||||
void UltraleapHandTracking::dispose_ultraleap() {
|
||||
|
@ -61,6 +79,8 @@ void UltraleapHandTracking::dispose_ultraleap() {
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
UtilityFunctions::print("Ultraleap was disposed of");
|
||||
}
|
||||
|
||||
void UltraleapHandTracking::_bind_methods() {
|
||||
|
@ -77,7 +97,7 @@ void UltraleapHandTracking::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("is_connected"), &UltraleapHandTracking::is_connected);
|
||||
ClassDB::bind_method(D_METHOD("is_started"), &UltraleapHandTracking::is_started);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_last_frame", "last_frame"), &UltraleapHandTracking::set_last_frame);
|
||||
//ClassDB::bind_method(D_METHOD("set_last_frame", "last_frame"), &UltraleapHandTracking::set_last_frame);
|
||||
ClassDB::bind_method(D_METHOD("get_last_frame"), &UltraleapHandTracking::get_last_frame);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_tracking_mode", "tracking_mode"), &UltraleapHandTracking::set_tracking_mode, DEFVAL(0));
|
||||
|
@ -118,7 +138,7 @@ void UltraleapHandTracking::_bind_methods() {
|
|||
"UltraleapFrame",
|
||||
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
|
||||
),
|
||||
"set_last_frame",
|
||||
"",
|
||||
"get_last_frame"
|
||||
);
|
||||
|
||||
|
@ -387,7 +407,6 @@ void UltraleapHandTracking::serviceMessageLoop() {
|
|||
LEAP_CONNECTION_MESSAGE msg;
|
||||
eLeapRS result;
|
||||
|
||||
keep_running = true;
|
||||
is_running = true;
|
||||
|
||||
while (keep_running) {
|
||||
|
@ -774,19 +793,6 @@ void UltraleapHandTracking::_notification(int p_what) {
|
|||
events.pop();
|
||||
}
|
||||
}
|
||||
else if (p_what == Node::NOTIFICATION_READY) {
|
||||
#if ANDROID_ENABLED
|
||||
// Get and store the binder
|
||||
if (Engine::get_singleton()->has_singleton("UltraleapBinder")) {
|
||||
binder = Engine::get_singleton()->get_singleton("UltraleapBinder");
|
||||
}
|
||||
#endif
|
||||
|
||||
// For now we will also start automatically if we're in the editor, so that we can have data for tool scripts
|
||||
if (autostart || Engine::get_singleton()->is_editor_hint()) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String UltraleapHandTracking::generate_connection_payload() {
|
||||
|
@ -805,7 +811,6 @@ void UltraleapHandTracking::set_primary_device(Ref<UltraleapDevice> device) {
|
|||
}
|
||||
// Pretty hack-ish, we open the device and re-store the handle in the UltraleapDevice object
|
||||
LeapOpenDevice(device->device_ref, &(device->device));
|
||||
LeapCreateClockRebaser(&(device->rebaser));
|
||||
|
||||
primary_device = device;
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class UltraleapHandTracking : public Node3D {
|
|||
GDCLASS(UltraleapHandTracking, Node3D);
|
||||
|
||||
public:
|
||||
UltraleapHandTracking();
|
||||
~UltraleapHandTracking();
|
||||
|
||||
void start();
|
||||
|
@ -39,11 +40,11 @@ public:
|
|||
bool get_interpolate();
|
||||
void set_interpolate(bool value);
|
||||
|
||||
UltraleapDeviceList* devices = memnew(UltraleapDeviceList);
|
||||
Ref<UltraleapDeviceList> devices = Ref<UltraleapDeviceList>(memnew(UltraleapDeviceList));
|
||||
|
||||
Ref<UltraleapFrame> last_frame_ref = Ref<UltraleapFrame>(memnew(UltraleapFrame));
|
||||
Ref<UltraleapImage> left_image_ref = Ref<UltraleapImage>(memnew(UltraleapImage));
|
||||
Ref<UltraleapImage> right_image_ref = Ref<UltraleapImage>(memnew(UltraleapImage));
|
||||
Ref<UltraleapFrame> last_frame_ref;
|
||||
Ref<UltraleapImage> left_image_ref;
|
||||
Ref<UltraleapImage> right_image_ref;
|
||||
|
||||
String service_ip = String("127.0.0.1");
|
||||
uint32_t service_port = 12345;
|
||||
|
@ -100,13 +101,10 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
bool _isRunning = false;
|
||||
|
||||
std::atomic<bool> is_running = false;
|
||||
std::atomic<bool> keep_running = false;
|
||||
std::atomic_bool is_running = ATOMIC_VAR_INIT(false);
|
||||
std::atomic_bool keep_running = ATOMIC_VAR_INIT(true);
|
||||
|
||||
LEAP_CONNECTION connectionHandle = NULL;
|
||||
LEAP_CLOCK_REBASER clockSynchronizer;
|
||||
|
||||
std::thread messageLoop;
|
||||
|
||||
|
@ -115,7 +113,6 @@ private:
|
|||
bool connected = false; /* We have confirmed connection */
|
||||
|
||||
Ref<UltraleapDevice> primary_device = NULL;
|
||||
|
||||
typedef struct {
|
||||
StringName signal;
|
||||
Variant arg;
|
||||
|
|
Loading…
Reference in New Issue