mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Merge pull request #6530 from smoogipoo/attempt-fix-macos-crashes
Attempt to fix crashes when loading textures on macOS
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace osu.Framework.Platform.Apple.Native
|
||||
{
|
||||
@@ -19,14 +20,9 @@ namespace osu.Framework.Platform.Apple.Native
|
||||
private static readonly IntPtr sel_init = Selector.Get("init");
|
||||
private static readonly IntPtr sel_drain = Selector.Get("drain");
|
||||
|
||||
[MustDisposeResource]
|
||||
public static NSAutoreleasePool Init()
|
||||
{
|
||||
var pool = alloc();
|
||||
Interop.SendIntPtr(pool.Handle, sel_init);
|
||||
return pool;
|
||||
}
|
||||
|
||||
private static NSAutoreleasePool alloc() => new NSAutoreleasePool(Interop.SendIntPtr(class_pointer, sel_alloc));
|
||||
=> new NSAutoreleasePool(Interop.SendIntPtr(Interop.SendIntPtr(class_pointer, sel_alloc), sel_init));
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace osu.Framework.Platform.MacOS
|
||||
using (NSAutoreleasePool.Init())
|
||||
{
|
||||
var nsData = NSData.FromBytes(stream.ToArray());
|
||||
using var nsImage = NSImage.LoadFromData(nsData);
|
||||
using var nsImage = NSImage.InitWithData(nsData);
|
||||
return setToPasteboard(nsImage.Handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace osu.Framework.Platform.MacOS
|
||||
var bytesSpan = new Span<byte>(nativeData.MutableBytes, length);
|
||||
stream.ReadExactly(bytesSpan);
|
||||
|
||||
using var nsImage = NSImage.LoadFromData(nativeData);
|
||||
using var nsImage = NSImage.InitWithData(nativeData);
|
||||
if (nsImage.Handle == IntPtr.Zero)
|
||||
throw new ArgumentException($"{nameof(Image)} could not be created from {nameof(stream)}.");
|
||||
|
||||
|
||||
@@ -28,21 +28,13 @@ namespace osu.Framework.Platform.MacOS.Native
|
||||
internal NSData TiffRepresentation => new NSData(Interop.SendIntPtr(Handle, sel_tiff_representation));
|
||||
|
||||
[MustDisposeResource]
|
||||
internal static NSImage LoadFromData(NSData data)
|
||||
{
|
||||
var image = alloc();
|
||||
Interop.SendIntPtr(image.Handle, sel_init_with_data, data);
|
||||
return image;
|
||||
}
|
||||
|
||||
internal void Release() => Interop.SendVoid(Handle, sel_release);
|
||||
|
||||
private static NSImage alloc() => new NSImage(Interop.SendIntPtr(class_pointer, sel_alloc));
|
||||
internal static NSImage InitWithData(NSData data)
|
||||
=> new NSImage(Interop.SendIntPtr(Interop.SendIntPtr(class_pointer, sel_alloc), sel_init_with_data, data));
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Handle != IntPtr.Zero)
|
||||
Release();
|
||||
Interop.SendVoid(Handle, sel_release);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user