Mercurial > octave-nkf
comparison src/graphics.cc @ 8341:b6c3b16d4cfa
Check validitity of handles to delete before deleting them to avoid issues with callbacks deleting the handles as well
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 24 Nov 2008 11:00:47 +0100 |
parents | 9238637cb81c |
children | 448188853722 |
comparison
equal
deleted
inserted
replaced
8340:fa9e6619fa99 | 8341:b6c3b16d4cfa |
---|---|
4580 | 4580 |
4581 const NDArray vals = args (0).array_value (); | 4581 const NDArray vals = args (0).array_value (); |
4582 | 4582 |
4583 if (! error_state) | 4583 if (! error_state) |
4584 { | 4584 { |
4585 // Check is all the handles to delete are valid first | |
4586 // as callbacks might delete one of the handles we | |
4587 // later want to delete | |
4585 for (octave_idx_type i = 0; i < vals.numel (); i++) | 4588 for (octave_idx_type i = 0; i < vals.numel (); i++) |
4586 { | 4589 { |
4587 h = gh_manager::lookup (vals.elem (i)); | 4590 h = gh_manager::lookup (vals.elem (i)); |
4588 | 4591 |
4589 if (h.ok ()) | 4592 if (! h.ok ()) |
4590 { | |
4591 graphics_object obj = gh_manager::get_object (h); | |
4592 | |
4593 // Don't do recursive deleting, due to callbacks | |
4594 if (! obj.get_properties ().is_beingdeleted ()) | |
4595 { | |
4596 graphics_handle parent_h = obj.get_parent (); | |
4597 | |
4598 graphics_object parent_obj = | |
4599 gh_manager::get_object (parent_h); | |
4600 | |
4601 // NOTE: free the handle before removing it from its | |
4602 // parent's children, such that the object's | |
4603 // state is correct when the deletefcn callback | |
4604 // is executed | |
4605 | |
4606 gh_manager::free (h); | |
4607 | |
4608 // A callback function might have already deleted | |
4609 // the parent | |
4610 if (parent_obj.valid_object ()) | |
4611 parent_obj.remove_child (h); | |
4612 | |
4613 Vdrawnow_requested = true; | |
4614 } | |
4615 } | |
4616 else | |
4617 { | 4593 { |
4618 error ("delete: invalid graphics object (= %g)", | 4594 error ("delete: invalid graphics object (= %g)", |
4619 vals.elem (i)); | 4595 vals.elem (i)); |
4620 break; | 4596 break; |
4597 } | |
4598 } | |
4599 | |
4600 if (! error_state) | |
4601 { | |
4602 for (octave_idx_type i = 0; i < vals.numel (); i++) | |
4603 { | |
4604 h = gh_manager::lookup (vals.elem (i)); | |
4605 | |
4606 if (h.ok ()) | |
4607 { | |
4608 graphics_object obj = gh_manager::get_object (h); | |
4609 | |
4610 // Don't do recursive deleting, due to callbacks | |
4611 if (! obj.get_properties ().is_beingdeleted ()) | |
4612 { | |
4613 graphics_handle parent_h = obj.get_parent (); | |
4614 | |
4615 graphics_object parent_obj = | |
4616 gh_manager::get_object (parent_h); | |
4617 | |
4618 // NOTE: free the handle before removing it from its | |
4619 // parent's children, such that the object's | |
4620 // state is correct when the deletefcn callback | |
4621 // is executed | |
4622 | |
4623 gh_manager::free (h); | |
4624 | |
4625 // A callback function might have already deleted | |
4626 // the parent | |
4627 if (parent_obj.valid_object ()) | |
4628 parent_obj.remove_child (h); | |
4629 | |
4630 Vdrawnow_requested = true; | |
4631 } | |
4632 } | |
4621 } | 4633 } |
4622 } | 4634 } |
4623 } | 4635 } |
4624 else | 4636 else |
4625 error ("delete: invalid graphics object"); | 4637 error ("delete: invalid graphics object"); |