Browse Source

Fixed some serialization and deserialization issues on opengl

Krzysztof Krysiński 2 weeks ago
parent
commit
d765810dcd

+ 2 - 0
src/ChunkyImageLib/ChunkyImage.cs

@@ -1314,6 +1314,7 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable, ICloneable, ICache
         lock (lockObject)
         lock (lockObject)
         {
         {
             ThrowIfDisposed();
             ThrowIfDisposed();
+            using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
             var dict = new Dictionary<VecI, Surface>();
             var dict = new Dictionary<VecI, Surface>();
             foreach (var (pos, chunk) in committedChunks[ChunkResolution.Full])
             foreach (var (pos, chunk) in committedChunks[ChunkResolution.Full])
             {
             {
@@ -1322,6 +1323,7 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable, ICloneable, ICache
                     var surf = new Surface(chunk.Surface.ImageInfo);
                     var surf = new Surface(chunk.Surface.ImageInfo);
                     surf.DrawingSurface.Canvas.DrawSurface(chunk.Surface.DrawingSurface, 0, 0);
                     surf.DrawingSurface.Canvas.DrawSurface(chunk.Surface.DrawingSurface, 0, 0);
                     dict[pos] = surf;
                     dict[pos] = surf;
+                    surf.DrawingSurface.Flush();
                 }
                 }
             }
             }
 
 

+ 3 - 0
src/PixiEditor/Helpers/SurfaceHelpers.cs

@@ -2,8 +2,10 @@
 using ChunkyImageLib;
 using ChunkyImageLib;
 using PixiEditor.Helpers.Extensions;
 using PixiEditor.Helpers.Extensions;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Bridge;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces.ImageData;
 using Drawie.Backend.Core.Surfaces.ImageData;
+using Drawie.Interop.Avalonia.Core;
 using Drawie.Numerics;
 using Drawie.Numerics;
 
 
 namespace PixiEditor.Helpers;
 namespace PixiEditor.Helpers;
@@ -38,6 +40,7 @@ public static class SurfaceHelpers
 
 
     public static unsafe byte[] ToByteArray(this Surface surface, ColorType colorType = ColorType.Bgra8888, AlphaType alphaType = AlphaType.Premul, ColorSpace colorSpace = null)
     public static unsafe byte[] ToByteArray(this Surface surface, ColorType colorType = ColorType.Bgra8888, AlphaType alphaType = AlphaType.Premul, ColorSpace colorSpace = null)
     {
     {
+        using var ctx = IDrawieInteropContext.Current.EnsureContext();
         int width = surface.Size.X;
         int width = surface.Size.X;
         int height = surface.Size.Y;
         int height = surface.Size.Y;
         var imageInfo = new ImageInfo(width, height, colorType, alphaType, colorSpace == null ? surface.ImageInfo.ColorSpace : colorSpace);
         var imageInfo = new ImageInfo(width, height, colorType, alphaType, colorSpace == null ? surface.ImageInfo.ColorSpace : colorSpace);

+ 1 - 0
src/PixiEditor/Models/Files/PixiFileType.cs

@@ -38,6 +38,7 @@ internal class PixiFileType : IoFileType
         catch (Exception e)
         catch (Exception e)
         {
         {
             CrashHelper.SendExceptionInfo(e);
             CrashHelper.SendExceptionInfo(e);
+            Console.WriteLine("Failed to save document: " + e.Message + Environment.NewLine + e.StackTrace);
             return new SaveResult(SaveResultType.UnknownError);
             return new SaveResult(SaveResultType.UnknownError);
         }
         }