Browse Source

Keep a reference to gobject while signal is attached

pull/875/head
Nikita Tsukanov 9 years ago
parent
commit
3bce0a9583
  1. 3
      src/Gtk/Avalonia.Gtk3/Interop/Native.cs
  2. 2
      src/Gtk/Avalonia.Gtk3/Interop/Signal.cs

3
src/Gtk/Avalonia.Gtk3/Interop/Native.cs

@ -210,6 +210,8 @@ namespace Avalonia.Gtk3.Interop
[UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gobject)]
public delegate void g_object_unref(IntPtr instance);
[UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gobject)]
public delegate void g_object_ref(GObject instance);
[UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gobject)]
public delegate ulong g_signal_connect_object(GObject instance, Utf8Buffer signal, IntPtr handler, IntPtr userData, int flags);
[UnmanagedFunctionPointer(CallingConvention.Cdecl), GtkImport(GtkDll.Gobject)]
public delegate ulong g_signal_handler_disconnect(GObject instance, ulong connectionId);
@ -272,6 +274,7 @@ namespace Avalonia.Gtk3.Interop
public static D.gtk_file_chooser_get_filenames GtkFileChooserGetFilenames;
public static D.gtk_dialog_add_button GtkDialogAddButton;
public static D.g_object_unref GObjectUnref;
public static D.g_object_ref GObjectRef;
public static D.g_signal_connect_object GSignalConnectObject;
public static D.g_signal_handler_disconnect GSignalHandlerDisconnect;
public static D.g_timeout_add GTimeoutAdd;

2
src/Gtk/Avalonia.Gtk3/Interop/Signal.cs

@ -18,6 +18,7 @@ namespace Avalonia.Gtk3.Interop
public ConnectedSignal(GObject instance, GCHandle handle, ulong id)
{
_instance = instance;
Native.GObjectRef(instance);
_handle = handle;
_id = id;
}
@ -26,6 +27,7 @@ namespace Avalonia.Gtk3.Interop
{
if (_handle.IsAllocated)
{
Native.GObjectUnref(_instance.DangerousGetHandle());
Native.GSignalHandlerDisconnect(_instance, _id);
_handle.Free();
}

Loading…
Cancel
Save