From 7af503b90c238facf096277ce5ec2ca97ff6c408 Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 25 Nov 2020 20:39:03 +0100 Subject: [PATCH] Do not try to resolve the palettized texture if there is no palette bound Fixes a crash in DRIV3R --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 27 +++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index 1fc4e9f18..78c5293d7 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -5956,14 +5956,27 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex if (bConvertToARGB) { EmuLog(LOG_LEVEL::DEBUG, "Unsupported texture format, expanding to D3DFMT_A8R8G8B8"); + // In case where there is a palettized texture without a palette attached, + // fill it with zeroes for now. This might not be correct, but it prevents a crash. + // Test case: DRIV3R + bool skipDueToNoPalette = false; + if (X_Format == xbox::X_D3DFMT_P8 && g_pXbox_Palette_Data[iTextureStage] == nullptr) { + LOG_TEST_CASE("Palettized texture bound without a palette"); + + memset(pDst, 0, dwDstRowPitch * dwMipHeight); + skipDueToNoPalette = true; + } + // Convert a row at a time, using a libyuv-like callback approach : - if (!ConvertD3DTextureToARGBBuffer( - X_Format, - pSrc, dwMipWidth, dwMipHeight, dwMipRowPitch, dwSrcSlicePitch, - pDst, dwDstRowPitch, dwDstSlicePitch, - dwDepth, - iTextureStage)) { - CxbxKrnlCleanup("Unhandled conversion!"); + if (!skipDueToNoPalette) { + if (!ConvertD3DTextureToARGBBuffer( + X_Format, + pSrc, dwMipWidth, dwMipHeight, dwMipRowPitch, dwSrcSlicePitch, + pDst, dwDstRowPitch, dwDstSlicePitch, + dwDepth, + iTextureStage)) { + CxbxKrnlCleanup("Unhandled conversion!"); + } } } else if (bSwizzled) {