From 6bfaf62cef0061782e9a6dc6fb7072226f44be4e Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 4 Dec 2023 23:46:14 +0100 Subject: [PATCH] SceneNodeData: fix fromNode() This currently fails to check the node passed and skips directly to the parent. --- river/SceneNodeData.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/river/SceneNodeData.zig b/river/SceneNodeData.zig index 536a714..fa079c1 100644 --- a/river/SceneNodeData.zig +++ b/river/SceneNodeData.zig @@ -51,13 +51,17 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void { } pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData { - var it: ?*wlr.SceneTree = node.parent; - while (it) |tree| : (it = tree.node.parent) { - if (@as(?*SceneNodeData, @ptrFromInt(tree.node.data))) |scene_node_data| { + var n = node; + while (true) { + if (@as(?*SceneNodeData, @ptrFromInt(n.data))) |scene_node_data| { return scene_node_data; } + if (n.parent) |parent_tree| { + n = &parent_tree.node; + } else { + return null; + } } - return null; } pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData {