Skip to content

Commit

Permalink
Merge pull request #93340 from RandomShaper/fix_anim_text_thread
Browse files Browse the repository at this point in the history
AnimatedTexture: Fix crash when loaded from a thread
  • Loading branch information
akien-mga authored Jun 19, 2024
2 parents cd87b0b + e6d930b commit 9a4942f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scene/resources/animated_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,18 @@ void AnimatedTexture::_bind_methods() {
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() {
//proxy = RS::get_singleton()->texture_create();
proxy_ph = RS::get_singleton()->texture_2d_placeholder_create();
proxy = RS::get_singleton()->texture_proxy_create(proxy_ph);

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() {
Expand Down
1 change: 1 addition & 0 deletions scene/resources/animated_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class AnimatedTexture : public Texture2D {
uint64_t prev_ticks = 0;

void _update_proxy();
void _finish_non_thread_safe_setup();

protected:
static void _bind_methods();
Expand Down

0 comments on commit 9a4942f

Please sign in to comment.