iOS端运行图片不显示copyTexImagesToTexture: Convert texImages to data buffers failed

stuka
Fri, 17 Apr 2026 01:37:03 +0000

Creator 版本： 3.8.7

目标平台：iOS 苹果8Plus

在构建到iOS端在苹果手机上运行部分图片不可见

iOS截图766×1006 57.2 KB

浏览器正常设置弹窗：

浏览器截图786×1018 108 KB

日志：14:20:24 [DEBUG]: JS: 设置按钮被点击
14:20:24 [DEBUG]: JS: [UIManager] [LOG] [Thu Apr 16 2026 14:20:24 GMT+0800 (CST)] show: PopSetting
V/AudioCache (193): id=2 _pcmData alloc: 0x11dd64000
V/AudioCache (226): pcm buffer was loaded successfully, total frames: 12672, total read frames: 12672, adjust frames: 0, remainingFrames: 0
V/AudioCache (235): id=2 generated alGenBuffers: 2429 for _pcmData: 0x11dd64000
V/AudioCache (236): id=2 _pcmData alBufferData: 0x11dd64000
14:20:24 [DEBUG]: JS: [UIManager] [LOG] [Thu Apr 16 2026 14:20:24 GMT+0800 (CST)] 加载: PopSetting
14:20:24 [DEBUG]: JS: [PopSetting] [LOG] [Thu Apr 16 2026 14:20:24 GMT+0800 (CST)] beforeShow
14:20:24 [DEBUG]: JS: [PopSetting] [LOG] [Thu Apr 16 2026 14:20:24 GMT+0800 (CST)] onShow
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed
14:20:24 [DEBUG]: JS: copyTexImagesToTexture: Convert texImages to data buffers failed

后面发现是 Cocos 引擎在 iOS 原生上的一个适配问题—— copyTexImagesToTexture 函数无法识别纹理数据类型，导致所有图片上传 GPU 失败。 copyTexImagesToTexture 函数只处理了两种类型：

HTMLCanvasElement → 取 texImage._data.data

HTMLImageElement → 取 texImage._data

但 iOS 原生下， ImageAsset.data 返回的是 第三种格式 （ _nativeData 对象，不是 HTMLImageElement 也不是 HTMLCanvasElement），所以直接走到了 else 分支报错返回 → 所有图片上传 GPU 失败 → 按钮图片全空 。

202604161523431906×1358 483 KB

后续修改

image1736×1092 276 KB

加粗示例
代码： else if (texImage._data) {
images.push(texImage._data);
} else if (texImage.data && texImage.data._data) {
In some cases, the ImageAsset object is passed, and the data attribute is the _nativeData
images.push(texImage.data._data);
}
我目前是直接修改的是构建之后的这个文件：build/ios/data/jsb-adapter/engine-adapter.js。
估计还要修改引擎里面的对应的这个JS文件：/Applications/Cocos/Creator/3.8.7/CocosCreator.app/Contents/Resources/resources/3d/engine/bin/adapter/native/engine-adapter.js
官方后续是否可以修复这个问题呢？

阅读整个主题