[banshee] Fix ImageSurface shared memory crash on Windows



commit 80c83bc23540dbbfd285b633364819a7c4152abf
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu Jul 2 15:12:51 2009 -0500

    Fix ImageSurface shared memory crash on Windows
    
    Based on patch from George Slavov.  Instead of using the faster
    PixbufImageSurface class, on Windows create ImageSurfaces via a
    Cairo Context (BGO #585496)

 .../Banshee.Collection.Gui/ArtworkManager.cs       |    2 +-
 .../Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs      |   31 ++++++++++++++++----
 2 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
index 234d19b..692be7a 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ArtworkManager.cs
@@ -125,7 +125,7 @@ namespace Banshee.Collection.Gui
             }
             
             try {
-                surface = new PixbufImageSurface (pixbuf);
+                surface = PixbufImageSurface.Create (pixbuf);
                 if (surface == null) {
                     return null;
                 }
diff --git a/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs b/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
index 1f13799..22311e3 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Gui/PixbufImageSurface.cs
@@ -51,21 +51,40 @@ namespace Hyena.Gui
             destroy_func = new cairo_destroy_func_t (DestroyPixelData);
         }
 
-        public static PixbufImageSurface Create (Gdk.Pixbuf pixbuf)
+        public static ImageSurface Create (Gdk.Pixbuf pixbuf)
         {
             return Create (pixbuf, false);
         }
 
-        public static PixbufImageSurface Create (Gdk.Pixbuf pixbuf, bool disposePixbuf)
+        public static ImageSurface Create (Gdk.Pixbuf pixbuf, bool disposePixbuf)
         {
             if (pixbuf == null || pixbuf.Handle == IntPtr.Zero) {
                 return null;
             }
 
-            try {
-                return new PixbufImageSurface (pixbuf, disposePixbuf);
-            } catch {
-                return null;
+            if (Hyena.PlatformUtil.IsRunningUnix) {
+                try {
+                    return new PixbufImageSurface (pixbuf, disposePixbuf);
+                } catch {
+                    return null;
+                }
+            } else {
+                // Windows has some trouble running the PixbufImageSurface, so as a
+                // workaround a slower but working version of this factory method is
+                // implemented. One day we can come back and optimize this by finding
+                // out what's causing the PixbufImageSurface to result in access
+                // violations when the object is disposed.
+                ImageSurface target = new ImageSurface (Format.ARGB32, pixbuf.Width, pixbuf.Height);
+                Context context = new Context (target);
+                Gdk.CairoHelper.SetSourcePixbuf (context, pixbuf, 0, 0);
+                context.Paint ();
+                ((IDisposable)context).Dispose ();
+
+                if (disposePixbuf) {
+                    ((IDisposable)pixbuf).Dispose ();
+                }
+
+                return target;
             }
         }
         



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]