Fixed the heap-use-after-free issue.

Just standard multithreading stuff; access to the allocator while hot
threads are running means stuff can change underneath us even /during/
a read.  I've mutex locked state for stuff in the drawing domain which
stops this issue.
This commit is contained in:
2025-12-12 04:29:32 +00:00
parent 5d78cb20df
commit a5666328b7
4 changed files with 12 additions and 4 deletions

View File

@@ -52,7 +52,7 @@ constexpr u64 clamp_to_width(const DrawState &ds, f64 val)
(val - ds.bounds.lower_val);
}
void draw_tree(const DrawState &ds, const State &state)
void draw_tree(DrawState &ds, State &state)
{
// Number line
DrawLine(0, HEIGHT / 2, WIDTH, HEIGHT / 2, WHITE);
@@ -63,6 +63,7 @@ void draw_tree(const DrawState &ds, const State &state)
DrawLine(lower_x, LINE_TOP, lower_x, LINE_BOTTOM, WHITE);
DrawLine(upper_x, LINE_TOP, upper_x, LINE_BOTTOM, WHITE);
state.mutex.lock();
std::stack<std::pair<u64, f64>> stack;
cw::node::Node n = state.allocator.get_val(0);
stack.push(std::make_pair(0, n.value.norm));
@@ -87,6 +88,7 @@ void draw_tree(const DrawState &ds, const State &state)
stack.push(std::make_pair(n.right, right.value.norm));
}
}
state.mutex.unlock();
}
using Clock = std::chrono::steady_clock;