@@ -766,6 +766,7 @@ pub struct AcquiredNodes<'i> {
766
766
document : & ' i Document ,
767
767
num_elements_acquired : usize ,
768
768
node_stack : Rc < RefCell < NodeStack > > ,
769
+ nodes_with_cycles : Vec < Node > ,
769
770
}
770
771
771
772
impl < ' i > AcquiredNodes < ' i > {
@@ -774,6 +775,7 @@ impl<'i> AcquiredNodes<'i> {
774
775
document,
775
776
num_elements_acquired : 0 ,
776
777
node_stack : Rc :: new ( RefCell :: new ( NodeStack :: new ( ) ) ) ,
778
+ nodes_with_cycles : Vec :: new ( ) ,
777
779
}
778
780
}
779
781
@@ -810,6 +812,10 @@ impl<'i> AcquiredNodes<'i> {
810
812
. lookup_node ( node_id)
811
813
. ok_or_else ( || AcquireError :: LinkNotFound ( node_id. clone ( ) ) ) ?;
812
814
815
+ if self . nodes_with_cycles . contains ( & node) {
816
+ return Err ( AcquireError :: CircularReference ( node. clone ( ) ) ) ;
817
+ }
818
+
813
819
if node. borrow_element ( ) . is_accessed_by_reference ( ) {
814
820
self . acquire_ref ( & node)
815
821
} else {
@@ -829,8 +835,11 @@ impl<'i> AcquiredNodes<'i> {
829
835
/// * At the drawing stage, `acquire_ref()` the pattern node that we already had, so that
830
836
/// its child elements that reference other paint servers will be able to detect circular
831
837
/// references to the pattern.
832
- pub fn acquire_ref ( & self , node : & Node ) -> Result < AcquiredNode , AcquireError > {
833
- if self . node_stack . borrow ( ) . contains ( node) {
838
+ pub fn acquire_ref ( & mut self , node : & Node ) -> Result < AcquiredNode , AcquireError > {
839
+ if self . nodes_with_cycles . contains ( node) {
840
+ Err ( AcquireError :: CircularReference ( node. clone ( ) ) )
841
+ } else if self . node_stack . borrow ( ) . contains ( node) {
842
+ self . nodes_with_cycles . push ( node. clone ( ) ) ;
834
843
Err ( AcquireError :: CircularReference ( node. clone ( ) ) )
835
844
} else {
836
845
self . node_stack . borrow_mut ( ) . push ( node) ;
0 commit comments