-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
class Scene extends NativeFieldWrapperClass1 {
@FfiNative<Void Function(Pointer<Void>)>('Scene::dispose')
external void dispose();
}
NativeFieldWrapperClass
es often share their identity between Dart and C++.
The first, and in this case only native field represents the C++ identity. The Dart object itself has the Dart identity.
If the C++ part has already been released/disposed/cleared, the native field is usually set to nullptr
(unboxed to 0
).
If the native field was never set (it is Dart null
), trying to call dispose()
will throw. However, if the native field has been cleared to nullptr
, a C call is made with C++ this
as nullptr
usually leading to a segfault in the native code.
We should check that the native field value is not nullptr
in addition to checking it for null
.
We should only do this check for FfiNative
instance methods on NativeFieldWrapperClass
es, and only for the automatically converted receiver. It is perfectly fine to pass nullptr
to a Foo*
argument to any argument of a top level function or to any argument (except for the receiver) of a C++ method.
Flutter issue: