feat(资源加载): 替换stb_image为SDL_image并添加脚本解析功能
- 将stb_image替换为SDL_image以解决Switch平台兼容性问题 - 添加PVF资源包解析器和脚本解析器功能 - 修改各平台配置文件添加SDL_image依赖 - 更新纹理加载逻辑使用SDL_image API - 新增脚本解析相关类用于处理游戏脚本数据
This commit is contained in:
68
.opencode/plans/stbi_switch_fix.md
Normal file
68
.opencode/plans/stbi_switch_fix.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Switch 平台 stbi_load_from_memory 崩溃修复计划
|
||||
|
||||
## 问题描述
|
||||
- 文件读取成功:129244 字节
|
||||
- 但调用 `stbi_load_from_memory()` 时直接崩溃
|
||||
- 说明 stbi_image 在 Switch 平台上有兼容性问题
|
||||
|
||||
## 可能的原因
|
||||
|
||||
1. **stbi_image 的内存分配问题** - stbi 默认使用 malloc/free,在 Switch 上可能有问题
|
||||
2. **缺少 stbi_image 的平台特定配置**
|
||||
3. **SIMD 优化问题** - stbi_image 的 ARM NEON 优化在 Switch 上可能有问题
|
||||
4. **栈溢出** - stbi_image 可能在栈上分配了太大的结构
|
||||
|
||||
## 修复方案
|
||||
|
||||
### 方案 1: 配置 stbi_image 使用自定义内存分配(推荐)
|
||||
修改 texture.cpp,在 include stb_image.h 之前定义自定义的内存分配函数。
|
||||
|
||||
### 方案 2: 禁用 stbi_image 的 SIMD 优化
|
||||
定义 `STBI_NO_SIMD` 来禁用 NEON 优化。
|
||||
|
||||
### 方案 3: 两者结合(最稳妥)
|
||||
同时使用自定义内存分配和禁用 SIMD 优化。
|
||||
|
||||
## 具体修复代码
|
||||
|
||||
修改 `Frostbite2D/src/frostbite2D/graphics/texture.cpp` 的开头部分:
|
||||
|
||||
```cpp
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
// 自定义 stbi_image 的内存分配函数
|
||||
#define STBI_MALLOC(sz) malloc(sz)
|
||||
#define STBI_REALLOC(p,sz) realloc(p,sz)
|
||||
#define STBI_FREE(p) free(p)
|
||||
|
||||
// 禁用 SIMD 优化,避免 Switch 平台兼容性问题
|
||||
#define STBI_NO_SIMD
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "SDL_log.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <frostbite2D/graphics/texture.h>
|
||||
#include <frostbite2D/utils/asset.h>
|
||||
#include <stb/stb_image.h>
|
||||
#include <glad/glad.h>
|
||||
```
|
||||
|
||||
## 额外调试建议
|
||||
|
||||
如果上述修复后仍然崩溃,可以添加更多调试来定位具体位置:
|
||||
|
||||
1. 在 stbi_load_from_memory 调用前后添加 printf
|
||||
2. 尝试用最简单的图片(小尺寸 BMP)测试
|
||||
3. 检查 stbi_image 的版本
|
||||
|
||||
## 测试步骤
|
||||
1. 应用修复
|
||||
2. 清理缓存并重新编译
|
||||
3. 运行测试
|
||||
4. 查看是否仍然崩溃
|
||||
|
||||
## 预期结果
|
||||
- stbi_load_from_memory 不再崩溃
|
||||
- 图片能够正常加载
|
||||
- LoadQ2 和 LoadQ3 日志能够正常输出
|
||||
Reference in New Issue
Block a user