Skip to content

Commit f78e9ac

Browse files
authored
Merge pull request #153 from SoGameStudio/master
修复(Unity):打开包工具面板时避免DX12崩溃
2 parents 55f72ee + 16d6891 commit f78e9ac

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/PackageKit/Markdown/MDHandlerImages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public AnimatedTexture GetAnimatedTexture()
9595

9696
while (img != null)
9797
{
98-
anim.Add(img.CreateTexture(), img.Delay / 1000.0f);
98+
anim.Add(img.CreateTexture(), img.Delay > 0 ? img.Delay / 1000.0f : 0.1f);
9999
img = decoder.NextImage();
100100
}
101101

QFramework.Unity2018+/Assets/QFramework/Toolkits/_CoreKit/PackageKit/Markdown/MDMGGifs.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,34 @@ public object Clone()
3636

3737
public Texture2D CreateTexture()
3838
{
39-
var tex = new Texture2D(Width, Height, TextureFormat.ARGB32, false)
39+
if (Width <= 0 || Height <= 0)
40+
{
41+
return Texture2D.blackTexture;
42+
}
43+
44+
var expectedPixelCount = Width * Height;
45+
var pixels = RawImage;
46+
47+
if (pixels == null || pixels.Length != expectedPixelCount)
48+
{
49+
var sanitizedPixels = new Color32[expectedPixelCount];
50+
51+
if (pixels != null && pixels.Length > 0)
52+
{
53+
Array.Copy(pixels, sanitizedPixels, Math.Min(pixels.Length, sanitizedPixels.Length));
54+
}
55+
56+
pixels = sanitizedPixels;
57+
}
58+
59+
// DX12 下 ARGB32 在部分 Unity 版本会触发底层纹理上传问题,RGBA32 更稳定。
60+
var tex = new Texture2D(Width, Height, TextureFormat.RGBA32, false)
4061
{
4162
filterMode = FilterMode.Point,
4263
wrapMode = TextureWrapMode.Clamp
4364
};
4465

45-
tex.SetPixels32(RawImage);
66+
tex.SetPixels32(pixels);
4667
tex.Apply();
4768

4869
return tex;
@@ -1102,4 +1123,4 @@ public static string Ident()
11021123
return $"{v} {e}{s}{b} {n}";
11031124
}
11041125
}
1105-
}
1126+
}

0 commit comments

Comments
 (0)