Fixed crash in import_texture_*()

This commit is contained in:
David Joslin 2023-11-08 12:59:32 -08:00 committed by Agent X
parent 5a5f33d859
commit 522d7c0373
2 changed files with 16 additions and 4 deletions

View file

@ -168,7 +168,7 @@ s32 act_idle(struct MarioState *m) {
// actionTimer is used to track how many cycles have passed.
if (++m->actionState == 3) {
f32 deltaYOfFloorBehindMario = m->pos[1] - find_floor_height_relative_polar(m, -0x8000, 60.0f);
if (deltaYOfFloorBehindMario < -24.0f || 24.0f < deltaYOfFloorBehindMario || (m->floor && (m->floor->flags & SURFACE_FLAG_DYNAMIC)) {
if (deltaYOfFloorBehindMario < -24.0f || 24.0f < deltaYOfFloorBehindMario || (m->floor && (m->floor->flags & SURFACE_FLAG_DYNAMIC))) {
m->actionState = 0;
} else {
// If Mario hasn't turned his head 10 times yet, stay idle instead of going to sleep.

View file

@ -126,6 +126,8 @@ static struct RSP {
struct LoadedVertex loaded_vertices[MAX_VERTICES + 4];
} rsp;
#define RDP_TILES 2
static struct RDP {
const uint8_t *palette;
struct {
@ -136,7 +138,7 @@ static struct RDP {
struct {
const uint8_t *addr;
uint32_t size_bytes;
} loaded_texture[2];
} loaded_texture[RDP_TILES];
struct {
uint8_t fmt;
uint8_t siz;
@ -144,7 +146,7 @@ static struct RDP {
uint16_t uls, ult, lrs, lrt; // U10.2
uint32_t line_size_bytes;
} texture_tile;
bool textures_changed[2];
bool textures_changed[RDP_TILES];
uint32_t other_mode_l, other_mode_h;
struct CombineMode combine_mode;
@ -200,7 +202,7 @@ static const uint8_t missing_texture[MISSING_W * MISSING_H * 4] = {
static bool sOnlyTextureChangeOnAddrChange = false;
static void gfx_update_loaded_texture(uint8_t tile_number, uint32_t size_bytes, const uint8_t* addr) {
if (tile_number > 1) { return; }
if (tile_number >= RDP_TILES) { return; }
if (!sOnlyTextureChangeOnAddrChange) {
rdp.textures_changed[tile_number] = true;
} else if (!rdp.textures_changed[tile_number]) {
@ -403,6 +405,7 @@ static bool gfx_texture_cache_lookup(int tile, struct TextureHashmapNode **n, co
}
static void import_texture_rgba32(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint32_t width = rdp.texture_tile.line_size_bytes / 2;
uint32_t height = (rdp.loaded_texture[tile].size_bytes / 2) / rdp.texture_tile.line_size_bytes;
@ -410,6 +413,7 @@ static void import_texture_rgba32(int tile) {
}
static void import_texture_rgba16(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint8_t rgba32_buf[8192];
@ -432,6 +436,7 @@ static void import_texture_rgba16(int tile) {
}
static void import_texture_ia4(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint8_t rgba32_buf[32768];
@ -456,6 +461,7 @@ static void import_texture_ia4(int tile) {
}
static void import_texture_ia8(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint8_t rgba32_buf[16384];
@ -478,6 +484,7 @@ static void import_texture_ia8(int tile) {
}
static void import_texture_ia16(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint8_t rgba32_buf[8192];
@ -500,6 +507,7 @@ static void import_texture_ia16(int tile) {
}
static void import_texture_i4(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint8_t rgba32_buf[32768];
@ -519,6 +527,7 @@ static void import_texture_i4(int tile) {
}
static void import_texture_i8(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint8_t rgba32_buf[16384];
@ -537,6 +546,7 @@ static void import_texture_i8(int tile) {
}
static void import_texture_ci4(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint8_t rgba32_buf[32768];
@ -561,6 +571,7 @@ static void import_texture_ci4(int tile) {
}
static void import_texture_ci8(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
uint8_t rgba32_buf[16384];
@ -584,6 +595,7 @@ static void import_texture_ci8(int tile) {
}
static void import_texture(int tile) {
tile = tile % RDP_TILES;
extern s32 dynos_tex_import(void **output, void *ptr, s32 tile, void *grapi, void **hashmap, void *pool, s32 *poolpos, s32 poolsize);
if (dynos_tex_import((void **) &rendering_state.textures[tile], (void *) rdp.loaded_texture[tile].addr, tile, gfx_rapi, (void **) gfx_texture_cache.hashmap, (void *) gfx_texture_cache.pool, (int *) &gfx_texture_cache.pool_pos, MAX_CACHED_TEXTURES)) { return; }
uint8_t fmt = rdp.texture_tile.fmt;