mirror of
https://github.com/Relintai/thread_pool.git
synced 2024-11-12 10:25:29 +01:00
Handle properly when use_threads is switched from false to true. Also make sure to check whether the update signal is connected or not before trying to set it up.
This commit is contained in:
parent
5f5ac160c5
commit
6990f8201a
@ -264,7 +264,23 @@ void ThreadPool::_worker_thread_func(void *user_data) {
|
||||
}
|
||||
|
||||
void ThreadPool::register_update() {
|
||||
SceneTree::get_singleton()->CONNECT("idle_frame", this, ThreadPool, update);
|
||||
if (!SceneTree::get_singleton()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SceneTree::get_singleton()->is_connected("idle_frame", this, "update")) {
|
||||
SceneTree::get_singleton()->CONNECT("idle_frame", this, ThreadPool, update);
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadPool::unregister_update() {
|
||||
if (!SceneTree::get_singleton()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SceneTree::get_singleton()->is_connected("idle_frame", this, "update")) {
|
||||
SceneTree::get_singleton()->DISCONNECT("idle_frame", this, ThreadPool, update);
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadPool::update() {
|
||||
@ -330,6 +346,8 @@ void ThreadPool::apply_settings() {
|
||||
|
||||
_threads.resize(0);
|
||||
|
||||
unregister_update();
|
||||
|
||||
_use_threads = _use_threads_new;
|
||||
|
||||
if (_use_threads) {
|
||||
@ -455,5 +473,7 @@ void ThreadPool::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("cancel_job_wait", "job"), &ThreadPool::cancel_job_wait);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("register_update"), &ThreadPool::register_update);
|
||||
ClassDB::bind_method(D_METHOD("unregister_update"), &ThreadPool::unregister_update);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("update"), &ThreadPool::update);
|
||||
}
|
||||
|
@ -99,6 +99,8 @@ public:
|
||||
static void _worker_thread_func(void *user_data);
|
||||
|
||||
void register_update();
|
||||
void unregister_update();
|
||||
|
||||
void update();
|
||||
void apply_settings();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user