Fixed crashes from callbacks.
authorOlle Håkansson <ollhak@gmail.com>
Mon, 21 Apr 2014 17:40:44 +0000 (19:40 +0200)
committerthefiddler <stapostol@gmail.com>
Thu, 24 Apr 2014 11:45:05 +0000 (13:45 +0200)
Source/OpenTK/Platform/MacOS/Cocoa/Class.cs

index fa73e09..6730837 100644 (file)
@@ -1,5 +1,6 @@
 using System.Runtime.InteropServices;
 using System;
+using System.Collections.Generic;
 
 namespace OpenTK.Platform.MacOS
 {
@@ -40,6 +41,8 @@ namespace OpenTK.Platform.MacOS
             objc_registerClassPair(handle);
         }
 
+        static List<Delegate> storedDelegates = new List<Delegate>();
+
         public static void RegisterMethod(IntPtr handle, Delegate d, string selector, string typeString)
         {
             // TypeString info:
@@ -52,6 +55,8 @@ namespace OpenTK.Platform.MacOS
             {
                 throw new ArgumentException("Could not register method " + d + " in class + " + class_getName(handle));
             }
+
+            storedDelegates.Add(d); // Don't let the garbage collector eat our delegates.
         }
     }
 }