Made DSLFunction gracefully handle parameter conversion failure

Previously, a failure in converting a parameter while creating a
function would result in an assertion failure. This fixes it to be a
non-fatal error.

Change-Id: I7a526eff9696847f70f0de78e71e7c23488c1254
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/404339
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2021-05-04 15:36:06 -04:00 committed by Skia Commit-Bot
parent 95b2cf912c
commit 6b3c6fca8b
2 changed files with 10 additions and 11 deletions

View File

@ -60,10 +60,16 @@ void DSLFunction::init(const DSLType& returnType, const char* name,
}
}
std::unique_ptr<SkSL::Variable> paramVar = DSLWriter::ParameterVar(*param);
SkASSERT(paramVar);
if (!paramVar) {
return;
}
paramVars.push_back(std::move(paramVar));
param->fDeclaration = nullptr;
}
SkASSERT(paramVars.size() == params.size());
for (size_t i = 0; i < params.size(); ++i) {
params[i]->fVar = paramVars[i].get();
}
fDecl = SkSL::FunctionDeclaration::Convert(DSLWriter::Context(),
*DSLWriter::SymbolTable(),
/*offset=*/-1,

View File

@ -238,16 +238,9 @@ std::unique_ptr<SkSL::Variable> DSLWriter::ParameterVar(DSLVar& var) {
// This should only be called on undeclared parameter variables, but we allow the creation to go
// ahead regardless so we don't have to worry about null pointers potentially sneaking in and
// breaking things. DSLFunction is responsible for reporting errors for invalid parameters.
std::unique_ptr<SkSL::Variable> skslVar = DSLWriter::IRGenerator().convertVar(
/*offset=*/-1,
var.fModifiers.fModifiers,
&var.fType.skslType(),
var.fName,
/*isArray=*/false,
/*arraySize=*/nullptr,
var.fStorage);
var.fVar = skslVar.get();
return skslVar;
return DSLWriter::IRGenerator().convertVar(/*offset=*/-1, var.fModifiers.fModifiers,
&var.fType.skslType(), var.fName, /*isArray=*/false,
/*arraySize=*/nullptr, var.fStorage);
}
std::unique_ptr<SkSL::Statement> DSLWriter::Declaration(DSLVar& var) {