Skip to content

Commit

Permalink
fix: return DalamudTextureWrap from LoadImageFromDxgiFormat(), cast e…
Browse files Browse the repository at this point in the history
…xplicitly
  • Loading branch information
goaaats committed Aug 8, 2023
1 parent 426e7f5 commit ebc4bac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Dalamud/Interface/Internal/InterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public bool SupportsDxgiFormat(Format dxgiFormat) => this.scene is null
/// <param name="height">The height in pixels.</param>
/// <param name="dxgiFormat">Format of the texture.</param>
/// <returns>A texture, ready to use in ImGui.</returns>
public TextureWrap LoadImageFromDxgiFormat(Span<byte> data, int pitch, int width, int height, Format dxgiFormat)
public IDalamudTextureWrap LoadImageFromDxgiFormat(Span<byte> data, int pitch, int width, int height, Format dxgiFormat)
{
if (this.scene == null)
throw new InvalidOperationException("Scene isn't ready.");
Expand Down Expand Up @@ -360,7 +360,7 @@ public TextureWrap LoadImageFromDxgiFormat(Span<byte> data, int pitch, int width
}

// no sampler for now because the ImGui implementation we copied doesn't allow for changing it
return new D3DTextureWrap(resView, width, height);
return new DalamudTextureWrap(new D3DTextureWrap(resView, width, height));
}

#nullable restore
Expand Down
6 changes: 5 additions & 1 deletion Dalamud/Interface/Internal/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public TextureManager(Framework framework, DataManager dataManager, InterfaceMan
throw new InvalidOperationException("Cannot create textures before scene is ready");

#pragma warning disable CS0618
return this.dataManager.GetImGuiTexture(file) as IDalamudTextureWrap;
return (IDalamudTextureWrap)this.dataManager.GetImGuiTexture(file);
#pragma warning restore CS0618
}

Expand Down Expand Up @@ -332,6 +332,10 @@ internal TextureInfo GetInfo(string path, bool refresh = true, bool rethrow = fa
// and we can't do anything about it. Return a dummy texture so that the plugin still
// has something to draw.
wrap = this.fallbackTextureWrap;

// Prevent divide-by-zero
if (info.Extents == Vector2.Zero)
info.Extents = Vector2.One;
}

info.Wrap = wrap;
Expand Down

0 comments on commit ebc4bac

Please sign in to comment.