Skip to content

Commit

Permalink
Fix #1677
Browse files Browse the repository at this point in the history
  • Loading branch information
Perksey committed Oct 10, 2023
1 parent 3ad600f commit 9187ad8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Lab/Experiments/BlankWindow/BlankWindow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Silk.NET.Windowing.VideoMode.AspectRatioEstimate.get -> Silk.NET.Maths.Vector2D<
Silk.NET.Windowing.WindowOptions.TopMost.get -> bool
Silk.NET.Windowing.WindowOptions.TopMost.set -> void
Silk.NET.Windowing.WindowOptions.WindowOptions(bool isVisible, Silk.NET.Maths.Vector2D<int> position, Silk.NET.Maths.Vector2D<int> size, double framesPerSecond, double updatesPerSecond, Silk.NET.Windowing.GraphicsAPI api, string! title, Silk.NET.Windowing.WindowState windowState, Silk.NET.Windowing.WindowBorder windowBorder, bool isVSync, bool shouldSwapAutomatically, Silk.NET.Windowing.VideoMode videoMode, int? preferredDepthBufferBits = null, int? preferredStencilBufferBits = null, Silk.NET.Maths.Vector4D<int>? preferredBitDepth = null, bool transparentFramebuffer = false, bool topMost = false, bool isEventDriven = false, Silk.NET.Core.Contexts.IGLContext? sharedContext = null, int? samples = null, string? windowClass = null, bool isContextControlDisabled = false) -> void
static Silk.NET.Windowing.Window.PrioritizeOrAdd<T>(System.Func<T>! factory, bool isFirstParty = false) -> T
33 changes: 32 additions & 1 deletion src/Windowing/Silk.NET.Windowing.Glfw/GlfwWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,45 @@ public override void SetWindowIcon(ReadOnlySpan<RawImage> icons)
throw new InvalidOperationException("Window should be initialized.");
}

var budget = 1024;
if (icons == null)
{
_glfw.SetWindowIcon(_glfwWindow, 0, null);
}
else
{
var images = stackalloc Image[icons.Length];
nint harr = 0;
var harrLen = 0;
var harrOff = 0;
for (var i = 0; i < icons.Length; i++)
{
var icon = icons[i];
// ReSharper disable once StackAllocInsideLoop
Span<byte> iconMemory = stackalloc byte[icon.Pixels.Length];
var iconMemory = budget >= icon.Pixels.Length
? stackalloc byte[icon.Pixels.Length]
: harr == 0
? null
: new Span<byte>((void*)(harr + harrOff), icon.Pixels.Length);
if (iconMemory == null)
{
for (var j = i; j < icons.Length; j++)
{
harrLen += icons[j].Pixels.Length;
}

harr = SilkMarshal.Allocate(harrLen);
iconMemory = new Span<byte>((void*) harr, icon.Pixels.Length);
harrOff = icon.Pixels.Length;
}
else if (budget >= icon.Pixels.Length)
{
budget -= icon.Pixels.Length;
}
else
{
harrOff += icon.Pixels.Length;
}
images[i] = new()
{
Width = icon.Width, Height = icon.Height,
Expand All @@ -446,6 +473,10 @@ public override void SetWindowIcon(ReadOnlySpan<RawImage> icons)
}

_glfw.SetWindowIcon(_glfwWindow, icons.Length, images);
if (harr != 0)
{
SilkMarshal.Free(harr);
}
GLFW.Glfw.ThrowExceptions();
}
}
Expand Down

0 comments on commit 9187ad8

Please sign in to comment.