Skip to content

fix: v3 OpenGL 纹理文件缺失或无法解码时段错误 - #149

Merged
Arkueid merged 1 commit into
EasyLive2D:mainfrom
zzoraemon043:fix/v3-missing-texture-crash
Oct 18, 2026
Merged

Arkueid merged 1 commit into
EasyLive2D:mainfrom
zzoraemon043:fix/v3-missing-texture-crash

Conversation

@zzoraemon043

Copy link
Copy Markdown
Contributor

问题

live2d.v3(OpenGL 后端)加载模型时,如果 model3.json 中引用的纹理文件不存在,进程会直接以 0xC0000005 退出,没有任何 Python 异常或错误日志。由于 stdout 缓冲在崩溃时丢失,最后看到的日志停在 load motion: ...,看起来像是动作加载后崩溃,与 #148 描述的现象一致。

原因

LAppTextureManager::CreateTextureFromPngFile(OpenGL 版)没有检查返回值:

  • LoadFileAsBytes 返回 NULL 时,size 未初始化,随后 stbi_load_from_memory(NULL, <垃圾值>) 读空指针 → 段错误
  • PNG 解码失败时 png == NULL,width/height 未初始化,仍会被传给 glTexImage2D

Vulkan 版本已经有这两处检查,OpenGL 版本缺失。

修改

  • OpenGL 版 CreateTextureFromPngFile:补上与 Vulkan 版一致的检查,LOGE 后返回 NULL
  • Model::SetupTextures:纹理创建失败时跳过,不再解引用空指针

测试

Windows 11 / Python 3.11 / CsmSDK 5-r.5,本地源码编译:

场景 修改前 (PyPI 1.0.0) 修改后
纹理文件不存在 段错误退出(exit 139) [E] couldn't load texture file: ...,模型正常加载、绘制
纹理文件不是合法 PNG 无报错、使用未初始化尺寸 [E] couldn't decode texture image: ...,正常继续
PSD2Live 导出的正常模型(tml / ds 示例等) 正常 正常

tests/test_model_json.py:38 passed(另 1 个 error 为既有问题:辅助函数 test(fn) 被 pytest 当作测试收集,与本 PR 无关)。

Refs #148 —— 这能把 #148 的静默崩溃变成明确的报错;是否就是该模型的具体原因,还需要原作者确认纹理路径。

OpenGL 路径的 CreateTextureFromPngFile 未检查 LoadFileAsBytes / stbi_load_from_memory
的返回值:文件不存在时以 NULL 指针和未初始化的 size 调用 stbi,直接 0xC0000005 退出,
且无任何报错。补上与 Vulkan 路径一致的检查并返回 NULL,SetupTextures 跳过失败的纹理。

Refs EasyLive2D#148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants