egui_node_graph icon indicating copy to clipboard operation
egui_node_graph copied to clipboard

Cannot use more than one node_graph in an egui app

Open bpostlethwaite opened this issue 2 years ago • 2 comments

NodeIds use slotmaps to hold references. Slotmaps return the same sequence of IDs for a given KeyType.

For example this runs with no panics

use slotmap::SlotMap;

fn main() {
    let mut sm1 = SlotMap::new();
    let mut sm2 = SlotMap::new();
    let sm1_key1 = sm1.insert("foo");
    let sm2_key1 = sm2.insert("bar");

    assert_eq!(sm1_key1, sm2_key1);
}

Egui Node Graph statically assigns the same KeyType to the node_graph slotmap and therefore multiple node_graphs in the same process will return the same keys. Since these keys go into the same "global" egui widget key-space egui complains about identical keys.

bpostlethwaite avatar Sep 01 '22 18:09 bpostlethwaite

Looking into this more it seems like it should be working. Egui seems to append the ID to the parents ID during hashing, and the parents should be different. I'm not sure why we see ID collisions with multiple node graph instances

bpostlethwaite avatar Sep 01 '22 22:09 bpostlethwaite

Hello, I encountered this problem, too. Actually I can have more than one node_graph in the egui app. The problem is when I want to show more than one at the same time. I'm using egui_tiles and until I drag one of them to have two visible at the same time it works. It would be nice to have that fixed. Thanks in advance.

edulecom avatar Sep 21 '23 18:09 edulecom