@@ -45,13 +45,13 @@ struct FlAccessibleNodePrivate {
4545 AtkObject parent_instance;
4646
4747 // Weak reference to the engine this node is created for.
48- FlEngine* engine;
48+ GWeakRef engine;
4949
5050 // / The unique identifier of the view to which this node belongs.
5151 FlutterViewId view_id;
5252
5353 // Weak reference to the parent node of this one or %NULL.
54- AtkObject* parent;
54+ GWeakRef parent;
5555
5656 int32_t node_id;
5757 gchar* name;
@@ -152,10 +152,7 @@ static void fl_accessible_node_set_property(GObject* object,
152152 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE (object);
153153 switch (prop_id) {
154154 case PROP_ENGINE :
155- g_assert (priv->engine == nullptr );
156- priv->engine = FL_ENGINE (g_value_get_object (value));
157- g_object_add_weak_pointer (object,
158- reinterpret_cast <gpointer*>(&priv->engine ));
155+ g_weak_ref_init (&priv->engine , g_value_get_object (value));
159156 break ;
160157 case PROP_VIEW_ID :
161158 priv->view_id = g_value_get_int64 (value);
@@ -172,16 +169,8 @@ static void fl_accessible_node_set_property(GObject* object,
172169static void fl_accessible_node_dispose (GObject* object) {
173170 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE (object);
174171
175- if (priv->engine != nullptr ) {
176- g_object_remove_weak_pointer (object,
177- reinterpret_cast <gpointer*>(&(priv->engine )));
178- priv->engine = nullptr ;
179- }
180- if (priv->parent != nullptr ) {
181- g_object_remove_weak_pointer (object,
182- reinterpret_cast <gpointer*>(&(priv->parent )));
183- priv->parent = nullptr ;
184- }
172+ g_weak_ref_clear (&priv->engine );
173+ g_weak_ref_clear (&priv->parent );
185174 g_clear_pointer (&priv->name , g_free);
186175 g_clear_pointer (&priv->actions , g_ptr_array_unref);
187176 g_clear_pointer (&priv->children , g_ptr_array_unref);
@@ -198,7 +187,8 @@ static const gchar* fl_accessible_node_get_name(AtkObject* accessible) {
198187// Implements AtkObject::get_parent.
199188static AtkObject* fl_accessible_node_get_parent (AtkObject* accessible) {
200189 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE (accessible);
201- return priv->parent ;
190+ g_autoptr (AtkObject) parent = ATK_OBJECT (g_weak_ref_get (&priv->parent ));
191+ return parent;
202192}
203193
204194// Implements AtkObject::get_index_in_parent.
@@ -316,9 +306,10 @@ static void fl_accessible_node_get_extents(AtkComponent* component,
316306
317307 *x = 0 ;
318308 *y = 0 ;
319- if (priv->parent != nullptr ) {
320- atk_component_get_extents (ATK_COMPONENT (priv->parent ), x, y, nullptr ,
321- nullptr , coord_type);
309+ g_autoptr (AtkObject) parent = ATK_OBJECT (g_weak_ref_get (&priv->parent ));
310+ if (parent != nullptr ) {
311+ atk_component_get_extents (ATK_COMPONENT (parent), x, y, nullptr , nullptr ,
312+ coord_type);
322313 }
323314
324315 *x += priv->x ;
@@ -336,7 +327,8 @@ static AtkLayer fl_accessible_node_get_layer(AtkComponent* component) {
336327static gboolean fl_accessible_node_do_action (AtkAction* action, gint i) {
337328 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE (action);
338329
339- if (priv->engine == nullptr ) {
330+ g_autoptr (FlEngine) engine = FL_ENGINE (g_weak_ref_get (&priv->engine ));
331+ if (engine == nullptr ) {
340332 return FALSE ;
341333 }
342334
@@ -488,8 +480,12 @@ static void fl_accessible_node_perform_action_impl(
488480 FlutterSemanticsAction action,
489481 GBytes* data) {
490482 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE (self);
491- fl_engine_dispatch_semantics_action (priv->engine , priv->view_id ,
492- priv->node_id , action, data);
483+ g_autoptr (FlEngine) engine = FL_ENGINE (g_weak_ref_get (&priv->engine ));
484+ if (engine == nullptr ) {
485+ return ;
486+ }
487+ fl_engine_dispatch_semantics_action (engine, priv->view_id , priv->node_id ,
488+ action, data);
493489}
494490
495491static void fl_accessible_node_class_init (FlAccessibleNodeClass* klass) {
@@ -553,6 +549,7 @@ static void fl_accessible_node_action_interface_init(AtkActionIface* iface) {
553549
554550static void fl_accessible_node_init (FlAccessibleNode* self) {
555551 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE (self);
552+ g_weak_ref_init (&priv->parent , nullptr );
556553 priv->actions = g_ptr_array_new ();
557554 priv->children = g_ptr_array_new_with_free_func (g_object_unref);
558555}
@@ -571,10 +568,8 @@ void fl_accessible_node_set_parent(FlAccessibleNode* self,
571568 gint index) {
572569 g_return_if_fail (FL_IS_ACCESSIBLE_NODE (self));
573570 FlAccessibleNodePrivate* priv = FL_ACCESSIBLE_NODE_GET_PRIVATE (self);
574- priv->parent = parent;
571+ g_weak_ref_set (& priv->parent , parent) ;
575572 priv->index = index;
576- g_object_add_weak_pointer (G_OBJECT (self),
577- reinterpret_cast <gpointer*>(&(priv->parent )));
578573}
579574
580575void fl_accessible_node_set_children (FlAccessibleNode* self,
0 commit comments