Skip to content

Commit

Permalink
fixed the bug where Overlay crashes on close.
Browse files Browse the repository at this point in the history
Updated interface that loads the image from disk to also return image width/height.
  • Loading branch information
zaafar committed Sep 22, 2020
1 parent 64270fb commit 53fb5c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
<ItemGroup>
<PackageReference Include="Coroutine" Version="2.0.0" />
<PackageReference Include="ImGui.NET" Version="1.78.0" />
<PackageReference Include="Veldrid" Version="4.9.0-g99f48fc1fd" />
<PackageReference Include="Veldrid.ImageSharp" Version="4.9.0-g99f48fc1fd" />
<PackageReference Include="Veldrid.Sdl2" Version="4.9.0-g99f48fc1fd" />
<PackageReference Include="Veldrid.StartupUtilities" Version="4.9.0-g99f48fc1fd" />
<PackageReference Include="Veldrid" Version="4.9.0-g6e9e71e698" />
<PackageReference Include="Veldrid.ImageSharp" Version="4.9.0-g6e9e71e698" />
<PackageReference Include="Veldrid.Sdl2" Version="4.9.0-g6e9e71e698" />
<PackageReference Include="Veldrid.StartupUtilities" Version="4.9.0-g6e9e71e698" />
</ItemGroup>

</Project>
16 changes: 11 additions & 5 deletions ClickableTransparentOverlay/Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,14 @@ public static Point Size
/// save it on the disk before sending to this function. Reason for this
/// is to cache the Image Texture using filePath as the key.
/// </param>
/// <returns>
/// A pointer to the Texture in the Graphic Device.
/// </returns>
public static IntPtr AddOrGetImagePointer(string filePath)
/// <param name="handle">output pointer to the image in the graphic device.</param>
/// <param name="width">width of the loaded image.</param>
/// <param name="height">height of the loaded image.</param>
public static void AddOrGetImagePointer(
string filePath,
out IntPtr handle,
out uint width,
out uint height)
{
if (!loadedImages.TryGetValue(filePath, out Texture texture))
{
Expand All @@ -213,7 +217,9 @@ public static IntPtr AddOrGetImagePointer(string filePath)
loadedImages.Add(filePath, texture);
}

return imController.GetOrCreateImGuiBinding(graphicsDevice.ResourceFactory, texture);
width = texture.Width;
height = texture.Height;
handle = imController.GetOrCreateImGuiBinding(graphicsDevice.ResourceFactory, texture);
}

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion DriverProgram/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ private static IEnumerator<Wait> SubmitRenderLogic()
ImGui.NewLine();
if (File.Exists("image.png"))
{
ImGui.Image(Overlay.AddOrGetImagePointer("image.png"), new Vector2(256, 256));
Overlay.AddOrGetImagePointer(
"image.png",
out IntPtr imgPtr,
out uint w,
out uint h);
ImGui.Image(imgPtr, new Vector2(w, h));
}
else
{
Expand Down

0 comments on commit 53fb5c0

Please sign in to comment.