From f9337d034e8e081ded0e9cb0307452544fa9c8e8 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 17 Nov 2024 16:55:25 -0500 Subject: [PATCH] Work around not-found textures. As discussed in IRC and Discord, 3ds Max does some manipulation and pretty much always successfully loads the bitmap data. Unfortunately, we are trying to access the file manually here, which might be an absolute path to a file on another machine. This path may not be valid on our system, which fails, causing textures to be duplicated. --- .../MaxPlugin/MaxConvert/plBitmapCreator.cpp | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Sources/MaxPlugin/MaxConvert/plBitmapCreator.cpp b/Sources/MaxPlugin/MaxConvert/plBitmapCreator.cpp index dacb36462c..93a2d92b85 100644 --- a/Sources/MaxPlugin/MaxConvert/plBitmapCreator.cpp +++ b/Sources/MaxPlugin/MaxConvert/plBitmapCreator.cpp @@ -552,16 +552,23 @@ plBitmap *plBitmapCreator::ICreateTexture( plBitmapData *bd, const plLocation &l // Texture reuse optimization if( texture ) { - WIN32_FILE_ATTRIBUTE_DATA fileAttrib; - GetFileAttributesExW(bd->fileName.WideString().data(), GetFileExInfoStandard, &fileAttrib); - FILETIME &fileTime = fileAttrib.ftLastWriteTime; + WIN32_FILE_ATTRIBUTE_DATA fileAttrib{}; + if (GetFileAttributesExW(bd->fileName.WideString().data(), GetFileExInfoStandard, &fileAttrib) != FALSE) + { + FILETIME &fileTime = fileAttrib.ftLastWriteTime; - // If this texture has been modified since the last export, delete the old version but reuse the key - if (!texture->IsSameModifiedTime(fileTime.dwLowDateTime, fileTime.dwHighDateTime)) + // If this texture has been modified since the last export, delete the old version but reuse the key + if (!texture->IsSameModifiedTime(fileTime.dwLowDateTime, fileTime.dwHighDateTime)) + { + DeleteExportedBitmap( texture->GetKey() ); + texture = nullptr; + key = nullptr; + } + } + else { - DeleteExportedBitmap( texture->GetKey() ); - texture = nullptr; - key = nullptr; + // Well, this really sucks. We couldn't tell what the modify time is, so just pretend all is well (but assert in Debug mode) + hsAssert(0, ST::format("Couldn't get bitmap '{}' modify time: {}", bd->fileName, hsCOMError(hsLastWin32Error, GetLastError()).c_str())); } } @@ -644,10 +651,17 @@ plBitmap *plBitmapCreator::ICreateTexture( plBitmapData *bd, const plLocation &l } // Texture reuse optimization - WIN32_FILE_ATTRIBUTE_DATA fileAttrib; - GetFileAttributesExW(bd->fileName.WideString().data(), GetFileExInfoStandard, &fileAttrib); - FILETIME &fileTime = fileAttrib.ftLastWriteTime; - texture->SetModifiedTime(fileTime.dwLowDateTime, fileTime.dwHighDateTime); + WIN32_FILE_ATTRIBUTE_DATA fileAttrib{}; + if (GetFileAttributesExW(bd->fileName.WideString().data(), GetFileExInfoStandard, &fileAttrib) != FALSE) + { + FILETIME &fileTime = fileAttrib.ftLastWriteTime; + texture->SetModifiedTime(fileTime.dwLowDateTime, fileTime.dwHighDateTime); + } + else + { + // Well, this really sucks. We couldn't tell what the modify time is, so just pretend all is well (but assert in Debug mode) + hsAssert(0, ST::format("Couldn't set bitmap '{}' modify time: {}", bd->fileName, hsCOMError(hsLastWin32Error, GetLastError()).c_str())); + } // Add to our list of created textures and ref, since we have a hold of them IAddBitmap( texture );