我使用 stbi_load 具有以下功能:
void load_texture_from_file(const char *file, bool alpha, const char *name) {
Texture *tex;
tex = malloc(sizeof(Texture));
tex->name = name;
int width, height, channels;
unsigned char *data = stbi_load(file, &width, &height, &channels, 0);
generate_texture(width, height, data, tex, alpha);
stbi_image_free(data);
}
文件来自:
load_texture_from_file("/home/correct_folder/correct_name.png", true, "sprite");
使用 stbi_failure_reason() 没有错误,使用 gdb 检查数据内容时,我看到:
Thread 1 "a" hit Breakpoint 2, load_texture_from_file (file=0x555555579d18 "/home/correct_folder/correct_name.png",
alpha=true, name=0x555555579d12 "face") at resource_manager.c:25
25 generate_texture(width, height, data, tex, alpha);
(gdb) print data
$1 = (unsigned char *) 0x7ffff40c1010 ""
我错过了什么?