godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.84k stars 21.14k forks source link

Deleting freed object from scene causes game crash #38333

Open KoBeWi opened 4 years ago

KoBeWi commented 4 years ago

Godot version: 92d4a0c

Steps to reproduce:

  1. Enable "Sync Scene Changes"
  2. Make some object that gets deleted, e.g. Timer self-destructing with timeout connected to free
  3. Run the game and wait for the object to be deleted
  4. Remove it in the local tree in the editor
  5. Return to game
  6. It freezes and then proceeds to crash
akien-mga commented 4 years ago

Can you get a stacktrace of the crash?

KoBeWi commented 4 years ago

There's no backtrace. It's actually a freeze, I had the window closed but it was probably killed by OS. This happens in 3.2.1 too btw.

ThakeeNathees commented 4 years ago

@akien-mga it was an infinite loop at scene_debugger.cpp:_remove_and_keep_node_func():749 and I'm confused about the continue here, the'll never increase the loop count

for (Set<Node *>::Element *F = E->get().front(); F;) {

        Set<Node *>::Element *N = F->next();

        Node *n = F->get();
        // F = F->next(); <------------------------------------------ this will fix
        if (base && !base->is_a_parent_of(n))
            continue;

        if (!n->has_node(p_at))
            continue; // <---------------------- this line maks the loop infinite

        Node *n2 = n->get_node(p_at);

        n2->get_parent()->remove_child(n2);

        live_edit_remove_list[n][p_keep_id] = n2;

        F = N; // <--------------------------------------------- no need any more
    }