Fix material shader generation when material layer fails to load
This commit is contained in:
@@ -43,32 +43,15 @@ void MaterialGenerator::AddLayer(MaterialLayer* layer)
|
||||
MaterialLayer* MaterialGenerator::GetLayer(const Guid& id, Node* caller)
|
||||
{
|
||||
// Find layer first
|
||||
for (int32 i = 0; i < _layers.Count(); i++)
|
||||
for (MaterialLayer* layer : _layers)
|
||||
{
|
||||
if (_layers[i]->ID == id)
|
||||
{
|
||||
// Found
|
||||
return _layers[i];
|
||||
}
|
||||
if (layer->ID == id)
|
||||
return layer;
|
||||
}
|
||||
|
||||
// Load asset
|
||||
Asset* asset = Assets.LoadAsync<MaterialBase>(id);
|
||||
if (asset == nullptr || asset->WaitForLoaded(30000))
|
||||
{
|
||||
OnError(caller, nullptr, TEXT("Failed to load material asset."));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Special case for engine exit event
|
||||
if (Engine::ShouldExit())
|
||||
{
|
||||
// End
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Check if load failed
|
||||
if (!asset->IsLoaded())
|
||||
if (asset == nullptr || asset->WaitForLoaded(10 * 1000))
|
||||
{
|
||||
OnError(caller, nullptr, TEXT("Failed to load material asset."));
|
||||
return nullptr;
|
||||
@@ -79,13 +62,11 @@ MaterialLayer* MaterialGenerator::GetLayer(const Guid& id, Node* caller)
|
||||
Asset* iterator = asset;
|
||||
while (material == nullptr)
|
||||
{
|
||||
// Wait for material to be loaded
|
||||
if (iterator->WaitForLoaded())
|
||||
{
|
||||
OnError(caller, nullptr, TEXT("Material asset load failed."));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (iterator->GetTypeName() == MaterialInstance::TypeName)
|
||||
{
|
||||
auto instance = ((MaterialInstance*)iterator);
|
||||
|
||||
@@ -15,12 +15,14 @@ void MaterialGenerator::ProcessGroupLayers(Box* box, Node* node, Value& value)
|
||||
if (!id.IsValid())
|
||||
{
|
||||
OnError(node, box, TEXT("Missing material."));
|
||||
value = MaterialValue::InitForZero(VariantType::Void);
|
||||
break;
|
||||
}
|
||||
ASSERT(GetRootLayer() != nullptr && GetRootLayer()->ID.IsValid());
|
||||
if (id == GetRootLayer()->ID)
|
||||
{
|
||||
OnError(node, box, TEXT("Cannot use current material as layer."));
|
||||
value = MaterialValue::InitForZero(VariantType::Void);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -29,6 +31,7 @@ void MaterialGenerator::ProcessGroupLayers(Box* box, Node* node, Value& value)
|
||||
if (layer == nullptr)
|
||||
{
|
||||
OnError(node, box, TEXT("Cannot load material."));
|
||||
value = MaterialValue::InitForZero(VariantType::Void);
|
||||
break;
|
||||
}
|
||||
ASSERT(_layers.Contains(layer));
|
||||
|
||||
Reference in New Issue
Block a user