Skip to content

Commit 9a4942f

Browse files
authored
Merge pull request #93340 from RandomShaper/fix_anim_text_thread
AnimatedTexture: Fix crash when loaded from a thread
2 parents cd87b0b + e6d930b commit 9a4942f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

scene/resources/animated_texture.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,18 @@ void AnimatedTexture::_bind_methods() {
270270
BIND_CONSTANT(MAX_FRAMES);
271271
}
272272

273+
void AnimatedTexture::_finish_non_thread_safe_setup() {
274+
RenderingServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy));
275+
}
276+
273277
AnimatedTexture::AnimatedTexture() {
274278
//proxy = RS::get_singleton()->texture_create();
275279
proxy_ph = RS::get_singleton()->texture_2d_placeholder_create();
276280
proxy = RS::get_singleton()->texture_proxy_create(proxy_ph);
277281

278282
RenderingServer::get_singleton()->texture_set_force_redraw_if_visible(proxy, true);
279-
RenderingServer::get_singleton()->connect("frame_pre_draw", callable_mp(this, &AnimatedTexture::_update_proxy));
283+
284+
MessageQueue::get_main_singleton()->push_callable(callable_mp(this, &AnimatedTexture::_finish_non_thread_safe_setup));
280285
}
281286

282287
AnimatedTexture::~AnimatedTexture() {

scene/resources/animated_texture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class AnimatedTexture : public Texture2D {
6565
uint64_t prev_ticks = 0;
6666

6767
void _update_proxy();
68+
void _finish_non_thread_safe_setup();
6869

6970
protected:
7071
static void _bind_methods();

0 commit comments

Comments
 (0)