SpriteFromDisk: 2x2 DXT5 placeholder texture fails on newer Unity (sizes must be a multiple of 4)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Placeholder được tạo trong SpriteLoadRequest_SpriteFromDisk.Prefix tại IRBTModUtils/Patches/GifSupportPatches.cs, khoảng dòng 54, nơi new Texture2D(2, 2, TextureFormat.DXT5, false) được gọi trước LoadImage. Hãy đọc phương thức đó để xác nhận placeholder chỉ dùng cho constructor và LoadImage thay đổi kích thước nó. Đổi định dạng thành RGBA32 và kiểm tra các sprite PNG và JPG vẫn tải được. Hoàn thành khi constructor không còn ném ngoại lệ trên runtime Unity 6 và các chân dung hiển thị được.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This is an issue the affects the recent UCU version of Battletech, because its running on Unity 6, however updating the texture to avoid this issue is a very small change that I hope the maintainers are ok with.
Summary
SpriteLoadRequest_SpriteFromDisk.Prefix loads PNG and JPG sprites into a placeholder texture created as 2×2 DXT5:
texture2D = new Texture2D(2, 2, TextureFormat.DXT5, false);
if (!texture2D.LoadImage(numArray))
Unity 2018 (retail BattleTech) accepts this. Newer Unity versions reject compressed textures whose dimensions aren't a multiple of 4. The constructor throws, so every PNG/JPG sprite loaded from disk through this patch fails. The size of the image itself doesn't matter; 512×512 PNGs fail too.
This came up running BattleTech Advanced on BattleTech UCU, a Unity 6 port of the game (downstream report: InternetDadCo/BattleTech-UCU#3). It doesn't affect retail players today, but it will break any mod setup on a newer Unity runtime. The fix is a one-line change and is safe on Unity 2018 too.
Error
Unity [ERROR] Compressed GraphicsFormat RGBA Compressed DXT5|BC3 sRGB requires a texture size that is a multiple of 4
<mod> [WARNING] Unable to load image at: ...\Mods\BT Advanced Pilots\sprite\guiTxrPort_Gigs.png
Data.DataManager [ERROR] UnityEngine.UnityException: Failed to create texture because of invalid parameters.
at UnityEngine.Texture2D.Internal_Create (...)
at UnityEngine.Texture2D..ctor (System.Int32 width, System.Int32 height, UnityEngine.TextureFormat textureFormat, System.Boolean mipChain)
at IRBTModUtils.Patches.SpriteLoadRequest_SpriteFromDisk.Prefix (...)
In one BTA session this happened 45 times, for retail backer portraits and BTA pilot and event portraits. Downstream, the null sprite crashes PilotDef.DownsampleSprite during SGRoomManager.OnSimGameInitialize. The sim-game UI never finishes initialising, so the ship navigation menus stop responding.
Suggested fix
Use an uncompressed placeholder format:
texture2D = new Texture2D(2, 2, TextureFormat.RGBA32, false);
LoadImage resizes the texture to the image's size anyway, so the placeholder's format and size only matter for the constructor. If DXT5 compression is wanted for memory reasons, call texture2D.Compress(true) after LoadImage when width % 4 == 0 && height % 4 == 0.
Verified workaround
As a test, I patched the shipped IRBTModUtils.dll (REL_2.0.0) at the IL level. I changed the ldc.i4.s 12 (DXT5) operand of this constructor call to 4 (RGBA32), which is equivalent to the change above. After the patch, all sprites load, portraits display, and all sim-game menus work normally on the Unity 6 runtime.
- Ngôn ngữ chính
- C#
- Star
- 7
- Fork
- 4
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của BattletechModders/IRBTModUtils
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Tất cả issue của BattletechModders/IRBTModUtils
Issue tương tự
-
ready-for-agent tech-debt
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
DigiBanks99/menlo#640 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ci
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
OpenTabletDriver/OpenTabletDriver#5283 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
area / templates
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
bitfoundation/bitplatform#15109 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
aikido critical security
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
dequelabs/axe-core-nuget#305 ·