From d8c3269cc65e10ec20bf6198d4299e602c927c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 14 Mar 2023 17:52:40 +0100 Subject: [PATCH] Fix zipped texture packs (it didn't load the ini from the zip, the rest worked). Plus a few other things. --- GPU/Common/ReplacedTexture.cpp | 13 ++++++++----- GPU/Common/TextureReplacer.cpp | 8 ++++++-- GPU/D3D11/TextureCacheD3D11.cpp | 3 +-- GPU/Directx9/DrawEngineDX9.cpp | 4 +++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/GPU/Common/ReplacedTexture.cpp b/GPU/Common/ReplacedTexture.cpp index df7c917ae8..d4a788a813 100644 --- a/GPU/Common/ReplacedTexture.cpp +++ b/GPU/Common/ReplacedTexture.cpp @@ -232,20 +232,23 @@ void ReplacedTexture::Prepare(VFSBackend *vfs) { } } - delete desc_; - desc_ = nullptr; - if (levels_.empty()) { - // Bad. - WARN_LOG(G3D, "Failed to load texture"); + // No replacement found. + std::string name = TextureReplacer::HashName(desc_->cachekey, desc_->hash, 0); + INFO_LOG(G3D, "Failed to load replacement texture. %s", name.c_str()); SetState(ReplacementState::NOT_FOUND); levelData_ = nullptr; + delete desc_; + desc_ = nullptr; return; } levelData_->fmt = fmt; SetState(ReplacementState::ACTIVE); + delete desc_; + desc_ = nullptr; + if (threadWaitable_) threadWaitable_->Notify(); } diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index 57ab5b7d92..429c3aeb67 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -135,7 +135,7 @@ bool TextureReplacer::LoadIni() { } IniFile ini; - bool iniLoaded = ini.LoadFromVFS(g_VFS, (basePath_ / INI_FILENAME).ToString()); + bool iniLoaded = ini.LoadFromVFS(*dir, INI_FILENAME); if (iniLoaded) { if (!LoadIniValues(ini)) { @@ -183,7 +183,11 @@ bool TextureReplacer::LoadIni() { repl.second->vfs_ = vfs_; } - INFO_LOG(G3D, "Texture pack activated from '%s'", basePath_.c_str()); + if (vfsIsZip_) { + INFO_LOG(G3D, "Texture pack activated from '%s'", (basePath_ / ZIP_FILENAME).c_str()); + } else { + INFO_LOG(G3D, "Texture pack activated from '%s'", basePath_.c_str()); + } // The ini doesn't have to exist for the texture directory or zip to be valid. return true; diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index ffdf94c61a..70f0a4e941 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -301,7 +301,7 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { if (plan.replaceValid) { int blockSize = 0; if (Draw::DataFormatIsBlockCompressed(plan.replaced->Format(), &blockSize)) { - stride = ((mipWidth + 3) & ~3) * 4; // This stride value doesn't quite make sense to me, but it works. + stride = ((mipWidth + 3) & ~3) * blockSize / 4; // This stride value doesn't quite make sense to me, but it works? dataSize = plan.replaced->GetLevelDataSize(i); } else { int bpp = (int)Draw::DataFormatSizeInBytes(plan.replaced->Format()); @@ -364,7 +364,6 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { desc.Format = dstFmt; desc.MipLevels = levels; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - ASSERT_SUCCESS(device_->CreateTexture2D(&desc, subresData, &tex)); texture = tex; } else { diff --git a/GPU/Directx9/DrawEngineDX9.cpp b/GPU/Directx9/DrawEngineDX9.cpp index eddfcc5d29..ce59de44aa 100644 --- a/GPU/Directx9/DrawEngineDX9.cpp +++ b/GPU/Directx9/DrawEngineDX9.cpp @@ -129,7 +129,9 @@ void DrawEngineDX9::InitDeviceObjects() { } void DrawEngineDX9::DestroyDeviceObjects() { - draw_->SetInvalidationCallback(InvalidationCallback()); + if (draw_) { + draw_->SetInvalidationCallback(InvalidationCallback()); + } ClearTrackedVertexArrays(); }