wayland: wait for pre-apply damage thread before destroying a terminal instance

It's possible, but unlikely, that we've pushed a "pre-apply damage"
job to the renderer thread queue (or that we've pushed it, and the
a thread is now working on it) when we shutdown a terminal instance.

This is sometimes caught in an assertion in term_destroy(), where we
check the queue length is 0. Other times, or in release builds, we
might crash in the thread, or in the shutdown logic when freeing the
buffer chains associated with the terminal instance.

Fix by ensuring there's no pre-apply damage operation queued, or
running, before shutting down a terminal instance.

Closes #2263
This commit is contained in:
Daniel Eklöf 2026-01-28 09:44:57 +01:00
parent 0bf193ef81
commit c291194a4e
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 11 additions and 5 deletions

View file

@ -2288,8 +2288,8 @@ render_worker_thread(void *_ctx)
return -1;
}
static void
wait_for_preapply_damage(struct terminal *term)
void
render_wait_for_preapply_damage(struct terminal *term)
{
if (!term->render.preapply_last_frame_damage)
return;
@ -3325,7 +3325,7 @@ grid_render(struct terminal *term)
term->render.workers.preapplied_damage.buf != NULL))
{
clock_gettime(CLOCK_MONOTONIC, &start_wait_preapply);
wait_for_preapply_damage(term);
render_wait_for_preapply_damage(term);
clock_gettime(CLOCK_MONOTONIC, &stop_wait_preapply);
}
@ -4401,7 +4401,7 @@ delayed_reflow_of_normal_grid(struct terminal *term)
term->interactive_resizing.old_hide_cursor = false;
/* Invalidate render pointers */
wait_for_preapply_damage(term);
render_wait_for_preapply_damage(term);
shm_unref(term->render.last_buf);
term->render.last_buf = NULL;
term->render.last_cursor.row = NULL;
@ -4976,7 +4976,7 @@ damage_view:
tll_free(term->normal.scroll_damage);
tll_free(term->alt.scroll_damage);
wait_for_preapply_damage(term);
render_wait_for_preapply_damage(term);
shm_unref(term->render.last_buf);
term->render.last_buf = NULL;
term_damage_view(term);