From b6011b08209f1b41c2fc2fe8b1a1c43fe5c08486 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sun, 23 Mar 2025 22:51:35 -0400 Subject: Fix crash when closing node due to invalid settings pointer --- node.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/node.c b/node.c index 4ea724a..12ff261 100644 --- a/node.c +++ b/node.c @@ -297,11 +297,10 @@ bool node_pixels_to_buffer_pos(Node *node, vec2 wpos, TextBuffer **pbuffer, Buff } void node_frame(Ted *ted, Node *node, Rect r) { - const Settings *settings = ted_active_settings(ted); if (node->tabs) { bool is_active = node == ted->active_node; Font *font = ted->font; - const float border_thickness = settings->border_thickness; + const float border_thickness = ted_active_settings(ted)->border_thickness; const float char_height = text_font_char_height(font); float tab_bar_height = char_height + 2 * border_thickness; @@ -402,6 +401,9 @@ void node_frame(Ted *ted, Node *node, Rect r) { vec2_sub(ted_mouse_pos(ted), ted->dragging_tab_origin)); } + // IMPORTANT: don't just move this to the top of the function. + // - settings may be invalidated if we close a buffer. + const Settings *settings = ted_active_settings(ted); // tab border gl_geometry_rect_border(tab_rect, border_thickness, settings_color(settings, COLOR_BORDER)); rect_shrink(&tab_rect, border_thickness); @@ -462,6 +464,7 @@ void node_frame(Ted *ted, Node *node, Rect r) { buffer_rect.size.y -= tab_bar_height; buffer_render(buffer, buffer_rect); } else { + const Settings *settings = ted_active_settings(ted); float padding = settings->padding; // this node is a split Node *a = node->split_a, *b = node->split_b; -- cgit v1.2.3