Skip to content

Commit 652eec3

Browse files
committed
Fix a crash/incorrect rendering when detaching a window in some circumstances
Fixes #2173 Ensure all cell related GPU data is resent
1 parent a9928ec commit 652eec3

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ Changelog
44
|kitty| is a feature full, cross-platform, *fast*, GPU based terminal emulator.
55
To update |kitty|, :doc:`follow the instructions <binary>`.
66

7+
0.15.1 [future]
8+
--------------------
9+
10+
- Fix a crash/incorrect rendering when detaching a window in some circumstances
11+
(:iss:`2173`)
12+
13+
714
0.15.0 [2019-11-27]
815
--------------------
916

kitty/screen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ typedef struct {
7676
Selection selection;
7777
SelectionBoundary last_rendered_selection_start, last_rendered_selection_end, last_rendered_url_start, last_rendered_url_end;
7878
Selection url_range;
79-
bool use_latin1, selection_updated_once, is_dirty, scroll_changed;
79+
bool use_latin1, selection_updated_once, is_dirty, scroll_changed, reload_all_gpu_data;
8080
Cursor *cursor;
8181
SavepointBuffer main_savepoints, alt_savepoints;
8282
SavemodesBuffer modes_savepoints;

kitty/shaders.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G
239239

240240
// Send the uniform data
241241
rd = (struct CellRenderData*)map_vao_buffer(vao_idx, uniform_buffer, GL_WRITE_ONLY);
242-
if (UNLIKELY(screen->color_profile->dirty)) {
242+
if (UNLIKELY(screen->color_profile->dirty || screen->reload_all_gpu_data)) {
243243
copy_color_table_to_buffer(screen->color_profile, (GLuint*)rd, cell_program_layouts[CELL_PROGRAM].color_table.offset / sizeof(GLuint), cell_program_layouts[CELL_PROGRAM].color_table.stride / sizeof(GLuint));
244244
}
245245
// Cursor position
@@ -295,7 +295,7 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa
295295
|| screen->cursor->y != screen->last_rendered_cursor_y;
296296
bool disable_ligatures = screen->disable_ligatures == DISABLE_LIGATURES_CURSOR;
297297

298-
if (screen->scroll_changed || screen->is_dirty || (disable_ligatures && cursor_pos_changed)) {
298+
if (screen->reload_all_gpu_data || screen->scroll_changed || screen->is_dirty || (disable_ligatures && cursor_pos_changed)) {
299299
sz = sizeof(GPUCell) * screen->lines * screen->columns;
300300
address = alloc_and_map_vao_buffer(vao_idx, sz, cell_data_buffer, GL_STREAM_DRAW, GL_WRITE_ONLY);
301301
screen_update_cell_data(screen, address, fonts_data, disable_ligatures && cursor_pos_changed);
@@ -308,7 +308,7 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa
308308
screen->last_rendered_cursor_y = screen->cursor->y;
309309
}
310310

311-
if (screen_is_selection_dirty(screen)) {
311+
if (screen->reload_all_gpu_data || screen_is_selection_dirty(screen)) {
312312
sz = screen->lines * screen->columns;
313313
address = alloc_and_map_vao_buffer(vao_idx, sz, selection_buffer, GL_STREAM_DRAW, GL_WRITE_ONLY);
314314
screen_apply_selection(screen, address, sz);
@@ -453,8 +453,8 @@ draw_cells_interleaved_premult(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen
453453
}
454454

455455
static inline void
456-
set_cell_uniforms(float current_inactive_text_alpha) {
457-
if (!cell_uniform_data.constants_set) {
456+
set_cell_uniforms(float current_inactive_text_alpha, bool force) {
457+
if (!cell_uniform_data.constants_set || force) {
458458
cell_uniform_data.gploc = glGetUniformLocation(program_id(GRAPHICS_PROGRAM), "inactive_text_alpha");
459459
cell_uniform_data.gpploc = glGetUniformLocation(program_id(GRAPHICS_PREMULT_PROGRAM), "inactive_text_alpha");
460460
cell_uniform_data.cploc = glGetUniformLocation(program_id(CELL_PROGRAM), "inactive_text_alpha");
@@ -467,7 +467,7 @@ set_cell_uniforms(float current_inactive_text_alpha) {
467467
#undef S
468468
cell_uniform_data.constants_set = true;
469469
}
470-
if (current_inactive_text_alpha != cell_uniform_data.prev_inactive_text_alpha) {
470+
if (current_inactive_text_alpha != cell_uniform_data.prev_inactive_text_alpha || force) {
471471
cell_uniform_data.prev_inactive_text_alpha = current_inactive_text_alpha;
472472
#define S(prog, loc) { bind_program(prog); glUniform1f(cell_uniform_data.loc, current_inactive_text_alpha); }
473473
S(CELL_PROGRAM, cploc); S(CELL_FG_PROGRAM, cfploc); S(GRAPHICS_PROGRAM, gploc); S(GRAPHICS_PREMULT_PROGRAM, gpploc);
@@ -503,7 +503,8 @@ draw_cells(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GL
503503
bind_vertex_array(vao_idx);
504504

505505
float current_inactive_text_alpha = (!can_be_focused || screen->cursor_render_info.is_focused) && is_active_window ? 1.0f : (float)OPT(inactive_text_alpha);
506-
set_cell_uniforms(current_inactive_text_alpha);
506+
set_cell_uniforms(current_inactive_text_alpha, screen->reload_all_gpu_data);
507+
screen->reload_all_gpu_data = false;
507508
GLfloat w = (GLfloat)screen->columns * dx, h = (GLfloat)screen->lines * dy;
508509
// The scissor limits below are calculated to ensure that they do not
509510
// overlap with the pixels outside the draw area,

kitty/state.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ attach_window(id_type os_window_id, id_type tab_id, id_type id) {
219219
w->render_data.screen->cell_size.height != osw->fonts_data->cell_height
220220
) resize_screen(osw, w->render_data.screen, true);
221221
else screen_dirty_sprite_positions(w->render_data.screen);
222+
w->render_data.screen->reload_all_gpu_data = true;
222223
break;
223224
}
224225
}

0 commit comments

Comments
 (0)