Skip to content

Conversation

@xuhuisheng
Copy link
Contributor

@xuhuisheng xuhuisheng commented Dec 3, 2025

Issue Descripion

As described in #113453, if we first change parent node type, then paste child nodes, then move nodes in editor. We will attempt to move the invalid nodes from before the changes.

Solution

We can set pending_click_select = nullptr in paste_nodes() to prevent using invalid node.

Edited: We should clean tree_clicked = false after replace_node(), then later mouse click event won't select node by mistake.

replace-paste-move-crash.webm

Explaination

When we execute "change type", we click mouse right key to display context menu, which will trigger input() to mark tree_clicked = true and save pending_click_select = current_node.

if (mb->is_pressed() && tree->get_rect().has_point(tree->get_local_mouse_position())) {
tree_clicked = true;
} else if (!mb->is_pressed()) {
tree_clicked = false;
}

But after executing replace_node(), tree_clicked is still true. That makes when triggered _handle_select, the pending_click_select always updated.

void SceneTreeDock::_handle_select(Node *p_node) {
if (tree_clicked) {
pending_click_select = p_node;
} else {
_push_item(p_node);
}
}

Whenever we click mouse to trigger next input(), the pending_click_select will update to editor_selection with push_item. That makes the current selection changed and causes crash.

if (!mb->is_pressed() && pending_click_select) {
_push_item(pending_click_select);
pending_click_select = nullptr;
}

@xuhuisheng xuhuisheng requested a review from a team as a code owner December 3, 2025 03:42
@xuhuisheng xuhuisheng force-pushed the dev/replace-paste-crash branch from 4a6ca7c to 3852728 Compare December 3, 2025 09:03
@AThousandShips AThousandShips added bug topic:editor crash cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release labels Dec 3, 2025
@AThousandShips AThousandShips added this to the 4.6 milestone Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release crash topic:editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor crashed when moving multiple pasted nodes after changing the target(parent) node‘s type

2 participants