Skip to content

Instantly share code, notes, and snippets.

@knocte
Created November 14, 2013 14:57
Show Gist options
  • Select an option

  • Save knocte/7468217 to your computer and use it in GitHub Desktop.

Select an option

Save knocte/7468217 to your computer and use it in GitHub Desktop.
From d29a3f228af43ef4a35c91b7abd5b24151c3d635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20G=2E=20Aragoneses?= <knocte@gmail.com> Date: Thu, 14 Nov 2013 15:56:11 +0100 Subject: [PATCH] Cairo: don't use GLib.Timeout if no mainloop is running
cairo/Global.cs | 5 +++++
glib/MainLoop.cs | 2 ++
2 files changed, 7 insertions(+)
diff --git a/cairo/Global.cs b/cairo/Global.cs
index 0d61ba4..ea858a9 100644
--- a/cairo/Global.cs
+++ b/cairo/Global.cs
@@ -34,6 +34,11 @@ namespace Cairo
{
internal static void QueueUnref (Action<IntPtr> unref_native_function, IntPtr handle)
{
+ if (!GLib.MainLoop.Default.IsRunning) {
+ unref_native_function (handle);
+ return;
+ }
+
GLib.Timeout.Add (50, () => {
unref_native_function (handle);
return false;
diff --git a/glib/MainLoop.cs b/glib/MainLoop.cs
index 62eaadb..644a672 100644
--- a/glib/MainLoop.cs
+++ b/glib/MainLoop.cs
@@ -28,6 +28,8 @@ namespace GLib {
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_main_loop_new (IntPtr context, bool isRunning);
+ public static MainLoop Default = new MainLoop ();
+
public MainLoop () : this (MainContext.Default) { }
public MainLoop (MainContext context) : this (context, false) { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment