Merge pull request #93340 from RandomShaper/fix_anim_text_thread

AnimatedTexture: Fix crash when loaded from a thread
This commit is contained in:
Rémi Verschelde 2024-06-19 11:01:20 +02:00 committed by GitHub
commit 9a4942f2f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -270,13 +270,18 @@ void AnimatedTexture::_bind_methods() {
BIND_CONSTANT(MAX_FRAMES); BIND_CONSTANT(MAX_FRAMES);
} }
void AnimatedTexture::_finish_non_thread_safe_setup() {
RenderingServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy));
}
AnimatedTexture::AnimatedTexture() { AnimatedTexture::AnimatedTexture() {
//proxy = RS::get_singleton()->texture_create(); //proxy = RS::get_singleton()->texture_create();
proxy_ph = RS::get_singleton()->texture_2d_placeholder_create(); proxy_ph = RS::get_singleton()->texture_2d_placeholder_create();
proxy = RS::get_singleton()->texture_proxy_create(proxy_ph); proxy = RS::get_singleton()->texture_proxy_create(proxy_ph);
RenderingServer::get_singleton()->texture_set_force_redraw_if_visible(proxy, true); RenderingServer::get_singleton()->texture_set_force_redraw_if_visible(proxy, true);
RenderingServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy));
MessageQueue::get_main_singleton()->push_callable(callable_mp(this, &AnimatedTexture::_finish_non_thread_safe_setup));
} }
AnimatedTexture::~AnimatedTexture() { AnimatedTexture::~AnimatedTexture() {

View file

@ -65,6 +65,7 @@ private:
uint64_t prev_ticks = 0; uint64_t prev_ticks = 0;
void _update_proxy(); void _update_proxy();
void _finish_non_thread_safe_setup();
protected: protected:
static void _bind_methods(); static void _bind_methods();