Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

不支持 BC 的设备(A16)上 iOS 版闪退:贴图视图 R8Unorm → RGBA16Uint 断言失败

Closed
#4 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@v0lumehi is already working on this.

Since Oct 27, 2026.

  • #446 by @v0lumehi — open

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, ios
Domain
backend

Research direction

Start in nvn_mtl.m at attach() around line 1858 and tex_by_id(); the report traces the crash to a BC4 GPU encoded texture using an RGBA16Uint view when BC compression is unavailable. Read the texture format handling and reproduce on Mac with DM_TEST_NO_BC=1. Done means the texture view is handled without the Metal assertion while preserving the encoded texture content; also inspect the reported g_red_once bounds issue.

Written by the indexing model from the issue text.

Description

设备: iPhone 14 Pro(A16,supportsBCTextureCompression = NO),iOS 27.0
版本: main @ 9579030,档案 01007EF00011E000(1.9.0 更新)

现象
启动几秒后闪退,日志最后一行 SetDepthClamp 开:宿主暂忽略 之后紧跟:

_mtlValidateArgumentsForTextureViewOnDevice:1877: failed assertion `Texture Creation
source texture pixelFormat (MTLPixelFormatR8Unorm) not compatible with texture view pixelFormat (MTLPixelFormatRGBA16Uint).'

Mac 上可复现:DM_TEST_NO_BC=1(不用开调试层)。调用栈:

_mtlValidateArgumentsForTextureViewOnDevice
-[AGXTexture initWithTexture:pixelFormat:resourceIndex:]
attach            nvn_mtl.m:1858
rp_begin_ex_      nvn_mtl.m:1888
draw              nvn_mtl.m:4868
mtl_exec          nvn_mtl.m:5747
h_nvnQueueSubmitCommands  hle_nvn.c:846

原因
游戏在 GPU 上编码一张 BC4 贴图:通过 RGBA16Uint 视图往里画(NVN 贴图格式 0x49,视图格式 0x2c,一个像素对应一个 8 字节块)。无 BC 时 tex_desc 把这张贴图建成解压格式(R8Unorm),原始块视图没有对应的存储,Metal 直接断言。

我本地的绕过办法(nvn_mtl.m)

  • attach():bc_unpack(t->d.format) 为真且视图格式不是 BC 时,不挂这个附件(和上面压缩格式附件的处理一样),打一条红行。
  • tex_by_id():采样视图做同样判断,按空槽处理。

改完后 DM_TEST_NO_BC=1 下能读档进到野外,肉眼没看出画面差异;但 GPU 编码的那张 BC4 贴图内容丢了,正式修法可能要把写入的块解码回 R8 贴图(或保留一份原始块的影子贴图)。

顺带:g_red_once 声明为 84 个元素,但代码里用了 RED_ONCE(84, …),越界一位。

另外无 BC 时野外的内存占用约 3.9 GB(有 BC 时约 2.8 GB),在 6 GB 内存的 iPhone 上可能超过单个 App 的上限。

Dominant language
C
Stars
438
Forks
102
Avg merge
11h 32m
Merged PRs (30d)
30

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from seedds/nxnative

All issues in seedds/nxnative

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.