mirror of https://github.com/sm64pc/sm64pc.git
don't die after encountering a NULL texture
This commit is contained in:
parent
540a0387c9
commit
93030b02a3
|
@ -245,6 +245,7 @@ static inline u8 *convert_ia8_char(u8 c, u16 *tex, s16 w, s16 h) {
|
||||||
#ifdef EXTERNAL_TEXTURES
|
#ifdef EXTERNAL_TEXTURES
|
||||||
return (u8 *)tex; // the data's just a name
|
return (u8 *)tex; // the data's just a name
|
||||||
#else
|
#else
|
||||||
|
if (!tex) return NULL;
|
||||||
if (!charCache[c].used) {
|
if (!charCache[c].used) {
|
||||||
charCache[c].used = 1;
|
charCache[c].used = 1;
|
||||||
alloc_ia8_text_from_i1(charCache[c].data, tex, w, h);
|
alloc_ia8_text_from_i1(charCache[c].data, tex, w, h);
|
||||||
|
@ -305,6 +306,7 @@ static u8 *convert_ia4_char(u8 c, u8 *tex, s16 w, s16 h) {
|
||||||
#ifdef EXTERNAL_TEXTURES
|
#ifdef EXTERNAL_TEXTURES
|
||||||
return tex; // the data's just a name
|
return tex; // the data's just a name
|
||||||
#else
|
#else
|
||||||
|
if (!tex) return NULL;
|
||||||
if (!charCache[c].used) {
|
if (!charCache[c].used) {
|
||||||
charCache[c].used = 1;
|
charCache[c].used = 1;
|
||||||
alloc_ia4_tex_from_i1(charCache[c].data, tex, w, h);
|
alloc_ia4_tex_from_i1(charCache[c].data, tex, w, h);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -573,12 +574,39 @@ static bool preload_texture(const char *path) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void load_texture(const char *name) {
|
||||||
|
static char fpath[SYS_MAX_PATH];
|
||||||
|
int w, h;
|
||||||
|
const char *texname = name;
|
||||||
|
|
||||||
|
if (!texname[0]) {
|
||||||
|
fprintf(stderr, "empty texture name at %p\n", texname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(fpath, sizeof(fpath), "%s/%s.png", sys_data_path(), texname);
|
||||||
|
u8 *data = stbi_load(fpath, &w, &h, NULL, 4);
|
||||||
|
if (!data) {
|
||||||
|
fprintf(stderr, "could not load texture: `%s`\n", fpath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx_rapi->upload_texture(data, w, h);
|
||||||
|
stbi_image_free(data); // don't need this anymore
|
||||||
|
}
|
||||||
|
|
||||||
#endif // EXTERNAL_TEXTURES
|
#endif // EXTERNAL_TEXTURES
|
||||||
|
|
||||||
static void import_texture(int tile) {
|
static void import_texture(int tile) {
|
||||||
uint8_t fmt = rdp.texture_tile.fmt;
|
uint8_t fmt = rdp.texture_tile.fmt;
|
||||||
uint8_t siz = rdp.texture_tile.siz;
|
uint8_t siz = rdp.texture_tile.siz;
|
||||||
|
|
||||||
|
if (!rdp.loaded_texture[tile].addr) {
|
||||||
|
fprintf(stderr, "NULL texture: tile %d, format %d/%d, size %d\n",
|
||||||
|
tile, (int)fmt, (int)siz, (int)rdp.loaded_texture[tile].size_bytes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (gfx_texture_cache_lookup(tile, &rendering_state.textures[tile], rdp.loaded_texture[tile].addr, fmt, siz)) {
|
if (gfx_texture_cache_lookup(tile, &rendering_state.textures[tile], rdp.loaded_texture[tile].addr, fmt, siz)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -586,17 +614,7 @@ static void import_texture(int tile) {
|
||||||
#ifdef EXTERNAL_TEXTURES
|
#ifdef EXTERNAL_TEXTURES
|
||||||
// the "texture data" is actually a C string with the path to our texture in it
|
// the "texture data" is actually a C string with the path to our texture in it
|
||||||
// load it from an external image in our data path
|
// load it from an external image in our data path
|
||||||
static char fpath[SYS_MAX_PATH];
|
load_texture((const char*)rdp.loaded_texture[tile].addr);
|
||||||
int w, h;
|
|
||||||
const char *texname = (const char*)rdp.loaded_texture[tile].addr;
|
|
||||||
snprintf(fpath, sizeof(fpath), "%s/%s.png", sys_data_path(), texname);
|
|
||||||
u8 *data = stbi_load(fpath, &w, &h, NULL, 4);
|
|
||||||
if (!data) {
|
|
||||||
fprintf(stderr, "could not load texture: `%s`\n", fpath);
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
gfx_rapi->upload_texture(data, w, h);
|
|
||||||
stbi_image_free(data); // don't need this anymore
|
|
||||||
#else
|
#else
|
||||||
// the texture data is actual texture data
|
// the texture data is actual texture data
|
||||||
int t0 = get_time();
|
int t0 = get_time();
|
||||||
|
|
Loading…
Reference in New Issue