From 2a38ef6fd2c751014087b93aecd0111a48c99c08 Mon Sep 17 00:00:00 2001 From: Human Gamer <39096122+HumanGamer@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:17:21 -0500 Subject: [PATCH] Better error handling for missing textures --- engine/source/game/tsStatic.cpp | 23 +++++++- engine/source/interior/interiorInstance.cpp | 24 ++++++-- engine/source/materials/customMaterial.cpp | 38 +++++++++--- engine/source/materials/customMaterial.h | 2 +- engine/source/materials/material.cpp | 64 ++++++++++++++++++--- engine/source/materials/material.h | 2 +- 6 files changed, 132 insertions(+), 21 deletions(-) diff --git a/engine/source/game/tsStatic.cpp b/engine/source/game/tsStatic.cpp index 8b807388..4ffc671f 100644 --- a/engine/source/game/tsStatic.cpp +++ b/engine/source/game/tsStatic.cpp @@ -119,8 +119,29 @@ bool TSStatic::onAdd() bool foundAllMaterials = true; for (int i = 0; i < mShape->materialList->size(); i++) { Material* mat = mShape->materialList->getMappedMaterial(i); + if (mat != NULL) - foundAllMaterials = foundAllMaterials && mat->preloadTextures(); + { + //char errorBuff[4096]; + //errorBuff[0] = '\0'; + + Vector errorBuff; + foundAllMaterials = foundAllMaterials && mat->preloadTextures(errorBuff); + + if (!errorBuff.empty()) + { + Con::errorf(ConsoleLogEntry::General, "Error preloading material(%s):", mShape->materialList->getMaterialName(i)); + Con::errorf("{"); + for (U32 k = 0; k < errorBuff.size(); k++) + { + Con::errorf(" missing file %s", errorBuff[k]); + } + Con::errorf("}"); + } + + //if (dStrlen(errorBuff) > 0) + // Con::errorf(ConsoleLogEntry::General, "Error preloading material(%s):\n{%s\n}", mShape->materialList->getMaterialName(i), errorBuff); + } } if (!foundAllMaterials) { Con::errorf(ConsoleLogEntry::General, "Unable to load TSStatic due to missing materials: %s", mShapeName); diff --git a/engine/source/interior/interiorInstance.cpp b/engine/source/interior/interiorInstance.cpp index 18796dac..53728d39 100644 --- a/engine/source/interior/interiorInstance.cpp +++ b/engine/source/interior/interiorInstance.cpp @@ -380,10 +380,26 @@ bool InteriorInstance::onAdd() if (materialUsages.find(j) == materialUsages.end()) continue; Material* mat = pInterior->mMaterialList->getMappedMaterial(j); if (mat != NULL) - foundAllMaterials = foundAllMaterials && mat->preloadTextures(); + { + //char errorBuff[4096]; + //errorBuff[0] = '\0'; + Vector errorBuff; + foundAllMaterials = foundAllMaterials && mat->preloadTextures(errorBuff); + + if (!errorBuff.empty()) + { + Con::errorf(ConsoleLogEntry::General, "Error preloading material(%s):", pInterior->mMaterialList->getMaterialName(j)); + Con::errorf("{"); + for (U32 k = 0; k < errorBuff.size(); k++) + { + Con::errorf(" missing file %s", errorBuff[k]); + } + Con::errorf("}"); + } - if (!foundAllMaterials) - Con::errorf(ConsoleLogEntry::General, "missing texture for material: %s", pInterior->mMaterialList->getMaterialName(j)); + //if (dStrlen(errorBuff) > 0) + // Con::errorf(ConsoleLogEntry::General, "Error preloading material(%s):\n{%s\n}", pInterior->mMaterialList->getMaterialName(j), errorBuff); + } } } if (!foundAllMaterials) { @@ -391,7 +407,7 @@ bool InteriorInstance::onAdd() NetConnection::setLastError("Unable to load interior due to missing materials: %s", mInteriorFileName); return false; } - + if (!isClientObject()) diff --git a/engine/source/materials/customMaterial.cpp b/engine/source/materials/customMaterial.cpp index 83ab58aa..92527ef7 100644 --- a/engine/source/materials/customMaterial.cpp +++ b/engine/source/materials/customMaterial.cpp @@ -69,21 +69,45 @@ void CustomMaterial::initPersistFields() } -bool CustomMaterial::preloadTextures() +bool CustomMaterial::preloadTextures(Vector& errorBuffer) { - bool found = Parent::preloadTextures(); + bool found = Parent::preloadTextures(errorBuffer); for (int i = 0; i < MAX_TEX_PER_PASS; i++) { - found = found && (!texFilename[i] || didFindTexture(texFilename[i])); + bool foundTex = (!texFilename[i] || didFindTexture(texFilename[i])); + if (!foundTex) + { + errorBuffer.push_back(texFilename[i]); + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find texture: %s", errorBuffer, texFilename[i]); + } + found = found && foundTex; } for (int i = 0; i < MAX_PASSES; i++) { - found = found && (!pass[i] || pass[i]->preloadTextures()); + found = found && (!pass[i] || pass[i]->preloadTextures(errorBuffer)); } if (fallback != NULL) - found = found && fallback->preloadTextures(); - found = found && (!mShaderData->DXVertexShaderName || ResourceManager->find(mShaderData->getVertexShaderPath())); // Transfer shaders too lmao (attempt) - found = found && (!mShaderData->DXVertexShaderName || ResourceManager->find(mShaderData->getPixelShaderPath())); + found = found && fallback->preloadTextures(errorBuffer); + + bool foundVert = (!mShaderData->DXVertexShaderName || ResourceManager->find(mShaderData->getVertexShaderPath())); // Transfer shaders too lmao (attempt) + if (!foundVert) + { + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find vertex shader: %s", errorBuffer, + // mShaderData->getVertexShaderPath()); + + errorBuffer.push_back(mShaderData->getVertexShaderPath()); + } + found = found && foundVert; + + bool foundPixel = (!mShaderData->DXPixelShaderName || ResourceManager->find(mShaderData->getPixelShaderPath())); + if (!foundPixel) + { + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find pixel shader: %s", errorBuffer, + // mShaderData->getPixelShaderPath()); + + errorBuffer.push_back(mShaderData->getPixelShaderPath()); + } + found = found && foundPixel; return found; } diff --git a/engine/source/materials/customMaterial.h b/engine/source/materials/customMaterial.h index f8d6b0d6..c6b3d699 100644 --- a/engine/source/materials/customMaterial.h +++ b/engine/source/materials/customMaterial.h @@ -72,7 +72,7 @@ class CustomMaterial : public Material static void initPersistFields(); static void updateTime(); - virtual bool preloadTextures(); + virtual bool preloadTextures(Vector& errorBuffer); const char* mShaderDataName; ShaderData* mShaderData; diff --git a/engine/source/materials/material.cpp b/engine/source/materials/material.cpp index ffa59523..5f5aa53c 100644 --- a/engine/source/materials/material.cpp +++ b/engine/source/materials/material.cpp @@ -320,21 +320,71 @@ void Material::updateTime() } } -bool Material::preloadTextures() +bool Material::preloadTextures(Vector& errorBuffer) { bool found = true; for (int i = 0; i < MAX_STAGES; i++) { - found = found && (!baseTexFilename[i] || didFindTexture(baseTexFilename[i])); - found = found && (!detailFilename[i] || didFindTexture(detailFilename[i])); - found = found && (!bumpFilename[i] || didFindTexture(bumpFilename[i])); - found = found && (!envFilename[i] || didFindTexture(envFilename[i])); + bool foundBaseTex = (!baseTexFilename[i] || didFindTexture(baseTexFilename[i])); + if (!foundBaseTex) + { + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find base texture: %s", errorBuffer, + // baseTexFilename[i]); + + errorBuffer.push_back(baseTexFilename[i]); + } + found = found && foundBaseTex; + + bool foundDetail = (!detailFilename[i] || didFindTexture(detailFilename[i])); + if (!foundDetail) + { + errorBuffer.push_back(detailFilename[i]); + + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find detail texture: %s", errorBuffer, + // detailFilename[i]); + } + found = found && foundDetail; + + bool foundBump = (!bumpFilename[i] || didFindTexture(bumpFilename[i])); + if (!foundBump) + { + errorBuffer.push_back(bumpFilename[i]); + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find bump texture: %s", errorBuffer, + // bumpFilename[i]); + } + found = found && foundBump; + + bool foundEnv = (!envFilename[i] || didFindTexture(envFilename[i])); + if (!foundEnv) + { + errorBuffer.push_back(envFilename[i]); + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find env texture: %s", errorBuffer, + // envFilename[i]); + } + found = found && foundEnv; + } + bool foundNoiseTex = (!noiseTexFileName || didFindTexture(noiseTexFileName)); + if (!foundNoiseTex) + { + errorBuffer.push_back(noiseTexFileName); + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find noise texture: %s", errorBuffer, + // noiseTexFileName); } - found = found && (!noiseTexFileName || didFindTexture(noiseTexFileName)); + found = found && foundNoiseTex; + if (mCubemapData != NULL && !dynamicCubemap) { for (int i = 0; i < 6; i++) - found = found && (!mCubemapData->cubeFaceFile[i] || didFindTexture(mCubemapData->cubeFaceFile[i])); + { + bool foundCubemap = (!mCubemapData->cubeFaceFile[i] || didFindTexture(mCubemapData->cubeFaceFile[i])); + if (!foundCubemap) + { + errorBuffer.push_back(mCubemapData->cubeFaceFile[i]); + //dSprintf(errorBuffer, errorBufferSize, "%s\n Could not find cubemap face texture: %s", errorBuffer, + // mCubemapData->cubeFaceFile[i]); + } + found = found && foundCubemap; + } } return found; } diff --git a/engine/source/materials/material.h b/engine/source/materials/material.h index 0d7ac236..908fe36d 100644 --- a/engine/source/materials/material.h +++ b/engine/source/materials/material.h @@ -242,7 +242,7 @@ class Material : public SimObject bool isIFL(){ return mIsIFL; } bool isTranslucent() { return translucent || subPassTranslucent; } char* getPath() { return mPath; } - virtual bool preloadTextures(); + virtual bool preloadTextures(Vector& errorBuffer); bool didFindTexture(const char* path); void updateTimeBasedParams();