From 6b3c6fca8b296068dcdd1dda87fc06324b0a508a Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Tue, 4 May 2021 15:36:06 -0400 Subject: [PATCH] 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 Commit-Queue: Ethan Nicholas --- src/sksl/dsl/DSLFunction.cpp | 8 +++++++- src/sksl/dsl/priv/DSLWriter.cpp | 13 +++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/sksl/dsl/DSLFunction.cpp b/src/sksl/dsl/DSLFunction.cpp index 8b4937a031..449a3637d1 100644 --- a/src/sksl/dsl/DSLFunction.cpp +++ b/src/sksl/dsl/DSLFunction.cpp @@ -60,10 +60,16 @@ void DSLFunction::init(const DSLType& returnType, const char* name, } } std::unique_ptr 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, diff --git a/src/sksl/dsl/priv/DSLWriter.cpp b/src/sksl/dsl/priv/DSLWriter.cpp index 3f801545e6..4078aa334c 100644 --- a/src/sksl/dsl/priv/DSLWriter.cpp +++ b/src/sksl/dsl/priv/DSLWriter.cpp @@ -238,16 +238,9 @@ std::unique_ptr 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 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 DSLWriter::Declaration(DSLVar& var) {