@@ -29,14 +29,30 @@ use std::rc::Rc;
2929use std:: sync:: mpsc:: { Receiver , Sender } ;
3030use std:: sync:: Arc ;
3131
32+ /// Identifies a node graph, either the document graph or a node graph associated with a legacy layer.
33+ #[ derive( Clone , Copy , Hash , PartialEq , Eq , Debug ) ]
34+ pub enum GraphIdentifier {
35+ DocumentGraph ,
36+ LayerGraph ( LayerId ) ,
37+ }
38+
39+ impl GraphIdentifier {
40+ pub const fn new ( layer_id : Option < LayerId > ) -> Self {
41+ match layer_id {
42+ Some ( layer_id) => Self :: LayerGraph ( layer_id) ,
43+ None => Self :: DocumentGraph ,
44+ }
45+ }
46+ }
47+
3248pub struct NodeRuntime {
3349 pub ( crate ) executor : DynamicExecutor ,
3450 font_cache : FontCache ,
3551 receiver : Receiver < NodeRuntimeMessage > ,
3652 sender : InternalNodeGraphUpdateSender ,
3753 wasm_io : Option < WasmApplicationIo > ,
3854 imaginate_preferences : ImaginatePreferences ,
39- pub ( crate ) thumbnails : HashMap < Option < LayerId > , HashMap < NodeId , SvgSegmentList > > ,
55+ pub ( crate ) thumbnails : HashMap < GraphIdentifier , HashMap < NodeId , SvgSegmentList > > ,
4056 canvas_cache : HashMap < Vec < LayerId > , SurfaceId > ,
4157}
4258
@@ -57,7 +73,7 @@ pub(crate) struct GenerationResponse {
5773 generation_id : u64 ,
5874 result : Result < TaggedValue , String > ,
5975 updates : VecDeque < Message > ,
60- new_thumbnails : HashMap < Option < LayerId > , HashMap < NodeId , SvgSegmentList > > ,
76+ new_thumbnails : HashMap < GraphIdentifier , HashMap < NodeId , SvgSegmentList > > ,
6177}
6278
6379enum NodeGraphUpdate {
@@ -209,7 +225,8 @@ impl NodeRuntime {
209225 debug ! ( "SVG {}" , render. svg) ;
210226
211227 if let Some ( node_id) = node_path. get ( node_path. len ( ) - 2 ) . copied ( ) {
212- let old_thumbnail = self . thumbnails . entry ( layer_path. last ( ) . copied ( ) ) . or_default ( ) . entry ( node_id) . or_default ( ) ;
228+ let graph_identifier = GraphIdentifier :: new ( layer_path. last ( ) . copied ( ) ) ;
229+ let old_thumbnail = self . thumbnails . entry ( graph_identifier) . or_default ( ) . entry ( node_id) . or_default ( ) ;
213230 if * old_thumbnail != render. svg {
214231 * old_thumbnail = render. svg ;
215232 thumbnails_changed = true ;
@@ -263,7 +280,7 @@ pub struct NodeGraphExecutor {
263280 receiver : Receiver < NodeGraphUpdate > ,
264281 // TODO: This is a memory leak since layers are never removed
265282 pub ( crate ) last_output_type : HashMap < Vec < LayerId > , Option < Type > > ,
266- pub ( crate ) thumbnails : HashMap < Option < LayerId > , HashMap < NodeId , SvgSegmentList > > ,
283+ pub ( crate ) thumbnails : HashMap < GraphIdentifier , HashMap < NodeId , SvgSegmentList > > ,
267284 futures : HashMap < u64 , ExecutionContext > ,
268285}
269286
@@ -516,7 +533,7 @@ impl NodeGraphExecutor {
516533
517534 /// When a blob url for a thumbnail is loaded, update the state and the UI.
518535 pub fn insert_thumbnail_blob_url ( & mut self , blob_url : String , layer_id : Option < LayerId > , node_id : NodeId , responses : & mut VecDeque < Message > ) {
519- if let Some ( layer) = self . thumbnails . get_mut ( & layer_id) {
536+ if let Some ( layer) = self . thumbnails . get_mut ( & GraphIdentifier :: new ( layer_id) ) {
520537 if let Some ( segment) = layer. values_mut ( ) . flat_map ( |segments| segments. iter_mut ( ) ) . find ( |segment| * * segment == SvgSegment :: BlobUrl ( node_id) ) {
521538 * segment = SvgSegment :: String ( blob_url) ;
522539 responses. add ( NodeGraphMessage :: SendGraph { should_rerender : false } ) ;
0 commit comments