diff --git a/data/dynos_mgr_lvl.cpp b/data/dynos_mgr_lvl.cpp index 00818d20..3345c6f1 100644 --- a/data/dynos_mgr_lvl.cpp +++ b/data/dynos_mgr_lvl.cpp @@ -39,11 +39,12 @@ void DynOS_Lvl_ModShutdown() { auto& _CustomLevelScripts = DynOS_Lvl_GetArray(); while (_CustomLevelScripts.Count() > 0) { - auto& pair = _CustomLevelScripts[0]; - DynOS_Tex_Invalid(pair.second); - Delete(pair.second); - free((void*)pair.first); - _CustomLevelScripts.Remove(0); + for (auto& pair : _CustomLevelScripts) { + DynOS_Tex_Invalid(pair.second); + Delete(pair.second); + free((void*)pair.first); + } + _CustomLevelScripts.Clear(); } auto& _OverrideLevelScripts = DynosOverrideLevelScripts(); diff --git a/data/dynos_mgr_tex.cpp b/data/dynos_mgr_tex.cpp index a07f790f..f7a197a6 100644 --- a/data/dynos_mgr_tex.cpp +++ b/data/dynos_mgr_tex.cpp @@ -379,6 +379,7 @@ void DynOS_Tex_Activate(DataNode* aNode, bool aCustomTexture) { void DynOS_Tex_Deactivate(DataNode* aNode) { if (!aNode) { return; } + aNode->mData->mUploaded = false; // remove from custom textures auto& _DynosCustomTexs = DynosCustomTexs(); diff --git a/src/game/level_update.c b/src/game/level_update.c index 55a5aa5e..b8a4ed74 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -1781,6 +1781,10 @@ s32 init_level(void) { } smlua_call_event_hooks(HOOK_ON_LEVEL_INIT); + // clear texture 1 on level init -- can linger and corrupt textures otherwise + extern u8 gGfxPcResetTex1; + gGfxPcResetTex1 = 1; + return 1; } diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 8a6869ab..0bf0f711 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -63,6 +63,8 @@ #define HASHMAP_LEN (MAX_CACHED_TEXTURES * 2) #define HASH_MASK (HASHMAP_LEN - 1) +u8 gGfxPcResetTex1 = 0; + struct RGBA { uint8_t r, g, b, a; }; @@ -361,6 +363,10 @@ static struct ColorCombiner *gfx_lookup_or_create_color_combiner(struct CombineM return prev_combiner = comb; } +void gfx_texture_cache_clear(void) { + memset(&gfx_texture_cache, 0, sizeof(gfx_texture_cache)); +} + static bool gfx_texture_cache_lookup(int tile, struct TextureHashmapNode **n, const uint8_t *orig_addr, uint32_t fmt, uint32_t siz) { #ifdef EXTERNAL_DATA // hash and compare the data (i.e. the texture name) itself size_t hash = string_hash(orig_addr); @@ -1903,6 +1909,11 @@ struct GfxRenderingAPI *gfx_get_current_rendering_api(void) { } void gfx_start_frame(void) { + if (gGfxPcResetTex1 > 0) { + gGfxPcResetTex1--; + rdp.loaded_texture[1].addr = NULL; + rdp.loaded_texture[1].size_bytes = 0; + } gfx_wapi->handle_events(); gfx_wapi->get_dimensions(&gfx_current_dimensions.width, &gfx_current_dimensions.height); if (gfx_current_dimensions.height == 0) {