Fix segfault by moving "register" to the update call, rather than the draw one

This commit is contained in:
Mewrry the Kitty 2025-11-30 15:16:30 -06:00
parent d9bcf32e17
commit 70f888196f

13
main.rb
View file

@ -217,10 +217,12 @@ class Hex
@hexid = SecureRandom.uuid
@dead = false
end
def draw
def update
amidead?
$hex_bgs.register(@hexid, @text_props.bg_color)
end
def draw
amidead?
$hex_bgs[@text_props.bg_color].draw(
@x, @y, 0, 1, 1, Gosu::Color::WHITE
) # layer 0: hex-bg
@ -344,6 +346,13 @@ class HexagonTerminalWindow < Gosu::Window
end
print "\x1b[G\x1b[2K#{out}\x1b[#{new_text[2]+1}G"
end
# End of update should call hex updates
@hexes.each do |rex|
rex.each do |hex|
hex.update
end
end
end
def draw