setzer22 / egui_node_graph

Build your node graph applications in Rust, using egui
MIT License
718 stars 134 forks source link

Cannot use more than one node_graph in an egui app #60

Open bpostlethwaite opened 2 years ago

bpostlethwaite commented 2 years ago

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 commented 2 years ago

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

edulecom commented 1 year ago

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.