Clear texture 1 on level init (fixes corrupt level textures)

This commit is contained in:
MysterD 2023-06-27 15:38:08 -07:00
parent ba02695d89
commit db77e38c0d
4 changed files with 22 additions and 5 deletions

View File

@ -39,11 +39,12 @@ void DynOS_Lvl_ModShutdown() {
auto& _CustomLevelScripts = DynOS_Lvl_GetArray(); auto& _CustomLevelScripts = DynOS_Lvl_GetArray();
while (_CustomLevelScripts.Count() > 0) { while (_CustomLevelScripts.Count() > 0) {
auto& pair = _CustomLevelScripts[0]; for (auto& pair : _CustomLevelScripts) {
DynOS_Tex_Invalid(pair.second); DynOS_Tex_Invalid(pair.second);
Delete(pair.second); Delete(pair.second);
free((void*)pair.first); free((void*)pair.first);
_CustomLevelScripts.Remove(0); }
_CustomLevelScripts.Clear();
} }
auto& _OverrideLevelScripts = DynosOverrideLevelScripts(); auto& _OverrideLevelScripts = DynosOverrideLevelScripts();

View File

@ -379,6 +379,7 @@ void DynOS_Tex_Activate(DataNode<TexData>* aNode, bool aCustomTexture) {
void DynOS_Tex_Deactivate(DataNode<TexData>* aNode) { void DynOS_Tex_Deactivate(DataNode<TexData>* aNode) {
if (!aNode) { return; } if (!aNode) { return; }
aNode->mData->mUploaded = false;
// remove from custom textures // remove from custom textures
auto& _DynosCustomTexs = DynosCustomTexs(); auto& _DynosCustomTexs = DynosCustomTexs();

View File

@ -1781,6 +1781,10 @@ s32 init_level(void) {
} }
smlua_call_event_hooks(HOOK_ON_LEVEL_INIT); 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; return 1;
} }

View File

@ -63,6 +63,8 @@
#define HASHMAP_LEN (MAX_CACHED_TEXTURES * 2) #define HASHMAP_LEN (MAX_CACHED_TEXTURES * 2)
#define HASH_MASK (HASHMAP_LEN - 1) #define HASH_MASK (HASHMAP_LEN - 1)
u8 gGfxPcResetTex1 = 0;
struct RGBA { struct RGBA {
uint8_t r, g, b, a; 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; 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) { 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 #ifdef EXTERNAL_DATA // hash and compare the data (i.e. the texture name) itself
size_t hash = string_hash(orig_addr); size_t hash = string_hash(orig_addr);
@ -1903,6 +1909,11 @@ struct GfxRenderingAPI *gfx_get_current_rendering_api(void) {
} }
void gfx_start_frame(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->handle_events();
gfx_wapi->get_dimensions(&gfx_current_dimensions.width, &gfx_current_dimensions.height); gfx_wapi->get_dimensions(&gfx_current_dimensions.width, &gfx_current_dimensions.height);
if (gfx_current_dimensions.height == 0) { if (gfx_current_dimensions.height == 0) {