Weird bug in draw_tree
Seems near the 100,000 node mark, the vector craps itself? I keep getting "heap use after free" errors here when trying to access the allocator vector. Disabling fsan just leads to a segment fault near the same point. I think we might need to introduce our own vector :)
This commit is contained in:
27
src/main.cpp
27
src/main.cpp
@@ -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)
|
||||
void draw_tree(const DrawState &ds, const State &state)
|
||||
{
|
||||
// Number line
|
||||
DrawLine(0, HEIGHT / 2, WIDTH, HEIGHT / 2, WHITE);
|
||||
@@ -63,18 +63,29 @@ void draw_tree(const DrawState &ds)
|
||||
DrawLine(lower_x, LINE_TOP, lower_x, LINE_BOTTOM, WHITE);
|
||||
DrawLine(upper_x, LINE_TOP, upper_x, LINE_BOTTOM, WHITE);
|
||||
|
||||
std::stack<cw::node::Node> stack;
|
||||
stack.push(ds.state.allocator.get_val(0));
|
||||
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));
|
||||
while (!stack.empty())
|
||||
{
|
||||
auto n = stack.top();
|
||||
u64 node_index;
|
||||
f64 norm;
|
||||
std::tie(node_index, norm) = stack.top();
|
||||
stack.pop();
|
||||
u64 x = clamp_to_width(ds, n.value.norm);
|
||||
u64 x = clamp_to_width(ds, norm);
|
||||
DrawLine(x, LINE_TOP, x, LINE_BOTTOM, RED);
|
||||
|
||||
cw::node::Node n = state.allocator.get_val(node_index);
|
||||
if (n.left >= 0)
|
||||
stack.push(ds.state.allocator.get_val(n.left));
|
||||
{
|
||||
cw::node::Node left = state.allocator.get_val(n.left);
|
||||
stack.push(std::make_pair(n.left, left.value.norm));
|
||||
}
|
||||
if (n.right >= 0)
|
||||
stack.push(ds.state.allocator.get_val(n.right));
|
||||
{
|
||||
cw::node::Node right = state.allocator.get_val(n.right);
|
||||
stack.push(std::make_pair(n.right, right.value.norm));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +156,7 @@ int main(void)
|
||||
|
||||
ClearBackground(BLACK);
|
||||
BeginDrawing();
|
||||
draw_tree(draw_state);
|
||||
draw_tree(draw_state, state);
|
||||
DrawText(format_str.c_str(), WIDTH / 2 - format_str_width / 2, HEIGHT / 8,
|
||||
FONT_SIZE, WHITE);
|
||||
EndDrawing();
|
||||
|
||||
Reference in New Issue
Block a user