From 49ce6885ea4eda97afd05daa9c1648d671b1ef05 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Fri, 2 Jun 2023 15:37:38 +0300 Subject: [PATCH] turns out trying to access the position of a closed window results in an x error who could've known --- src/chatter_context.cr | 4 +++- src/window_context.cr | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/chatter_context.cr b/src/chatter_context.cr index 81ef726..c58d9bd 100644 --- a/src/chatter_context.cr +++ b/src/chatter_context.cr @@ -40,7 +40,9 @@ class Funfriend::ChatterContext < Funfriend::WindowContext def update_position if parent p = parent.not_nil! - window.position = (Vec2.new(p.window.position) + Vec2.new(p.window.size) / 2 + parent_relative_pos - window_size / 2).xy_i + if !p.closed + window.position = (Vec2.new(p.window.position) + Vec2.new(p.window.size) / 2 + parent_relative_pos - window_size / 2).xy_i + end end end diff --git a/src/window_context.cr b/src/window_context.cr index 19b1a8d..8dd6427 100644 --- a/src/window_context.cr +++ b/src/window_context.cr @@ -5,6 +5,7 @@ GLFW_FOCUS_ON_SHOW = 0x0002000C class Funfriend::WindowContext getter window : CrystGLFW::Window + property closed : Bool = false DEFAULT_HINTS = { # supposedly required on MacOS @@ -43,6 +44,7 @@ class Funfriend::WindowContext def close window.destroy + @closed = true end def clean_up