Skip to content

Commit

Permalink
Better error handling for missing textures
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed Mar 30, 2024
1 parent e83e4a1 commit 2a38ef6
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 21 deletions.
23 changes: 22 additions & 1 deletion engine/source/game/tsStatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*> 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);
Expand Down
24 changes: 20 additions & 4 deletions engine/source/interior/interiorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,34 @@ 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<const char*> 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) {
Con::errorf(ConsoleLogEntry::General, "Unable to load interior due to missing materials: %s", mInteriorFileName);
NetConnection::setLastError("Unable to load interior due to missing materials: %s", mInteriorFileName);
return false;
}



if (!isClientObject())
Expand Down
38 changes: 31 additions & 7 deletions engine/source/materials/customMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,45 @@ void CustomMaterial::initPersistFields()

}

bool CustomMaterial::preloadTextures()
bool CustomMaterial::preloadTextures(Vector<const char*>& 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;
}
Expand Down
2 changes: 1 addition & 1 deletion engine/source/materials/customMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CustomMaterial : public Material

static void initPersistFields();
static void updateTime();
virtual bool preloadTextures();
virtual bool preloadTextures(Vector<const char*>& errorBuffer);
const char* mShaderDataName;
ShaderData* mShaderData;

Expand Down
64 changes: 57 additions & 7 deletions engine/source/materials/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,71 @@ void Material::updateTime()
}
}

bool Material::preloadTextures()
bool Material::preloadTextures(Vector<const char*>& 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;
}
Expand Down
2 changes: 1 addition & 1 deletion engine/source/materials/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*>& errorBuffer);
bool didFindTexture(const char* path);

void updateTimeBasedParams();
Expand Down

0 comments on commit 2a38ef6

Please sign in to comment.