diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dde212b46..4128707de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: if: matrix.config.os == 'ubuntu-latest' run: dotnet format Source/gtk-sharp.sln --verify-no-changes --no-restore - name: Install Deps - run: pip3 install meson ninja + run: pip3 install meson ninja --break-system-packages - name: Install Windows Deps if: matrix.config.os == 'windows-latest' run: choco install winflexbison3 pkgconfiglite -y --allow-empty-checksum diff --git a/Source/glib/Object.cs b/Source/glib/Object.cs index 3d3b29725..88454dbc7 100644 --- a/Source/glib/Object.cs +++ b/Source/glib/Object.cs @@ -8,7 +8,7 @@ // Copyright (c) 2013 Andres G. Aragoneses // // This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the Lesser GNU General +// modify it under the terms of version 2 of the Lesser GNU General // Public License as published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, @@ -66,7 +66,7 @@ protected virtual void Dispose(bool disposing) { if (tref == null) return; - if (disposing) + if (disposing || !FinalizeOnMainThread) tref.Dispose(); else tref.QueueUnref(); @@ -76,6 +76,8 @@ protected virtual void Dispose(bool disposing) { public static bool WarnOnFinalize { get; set; } + public static bool FinalizeOnMainThread { get; set; } = true; + [DllImport(Global.GObjectNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern IntPtr g_object_ref(IntPtr raw); diff --git a/Source/glib/Opaque.cs b/Source/glib/Opaque.cs index 26593fae7..6a856bf4c 100644 --- a/Source/glib/Opaque.cs +++ b/Source/glib/Opaque.cs @@ -130,8 +130,12 @@ protected virtual void DisposeManagedResources() { protected virtual void DisposeUnmanagedResources() { if (!Owned || DisposeUnmanagedFunc == null) return; - FinalizerInfo info = new FinalizerInfo(DisposeUnmanagedFunc, Handle); - Timeout.Add(50, new TimeoutHandler(info.Handler)); + if (Object.FinalizeOnMainThread) { + FinalizerInfo info = new FinalizerInfo(DisposeUnmanagedFunc, Handle); + Timeout.Add(50, new TimeoutHandler(info.Handler)); + } else { + DisposeUnmanagedFunc(Handle); + } } protected internal bool Disposed { get; private set; } = false;