Fix #147786: Crash when connecting menu to float input
Compositor crashes when connecting a menu output to a float input, this is because no implicit conversion is supported between the two, and no handling was done in this case. To fix this, we fallback to a default value for unsupported implicit conversions. Pull Request: https://projects.blender.org/blender/blender/pulls/147801
This commit is contained in:
@@ -110,7 +110,8 @@ class MultiFunctionProcedureOperation : public PixelOperation {
|
||||
|
||||
/* Convert the given variable to the given expected type. This is done by adding an implicit
|
||||
* conversion function whose output variable will be returned. If no conversion is needed, the
|
||||
* given variable is returned as is. */
|
||||
* given variable is returned as is. If conversion is not possible, a fallback default variable
|
||||
* will b returned. */
|
||||
mf::Variable *convert_variable(mf::Variable *variable, const mf::DataType expected_type);
|
||||
|
||||
/* Returns true if the operation operates on single values, that is, all of its inputs are single
|
||||
|
||||
@@ -444,6 +444,7 @@ void MultiFunctionProcedureOperation::populate_operation_result(DOutputSocket ou
|
||||
mf::Variable *MultiFunctionProcedureOperation::convert_variable(mf::Variable *variable,
|
||||
const mf::DataType expected_type)
|
||||
{
|
||||
/* Conversion not needed. */
|
||||
const mf::DataType variable_type = variable->data_type();
|
||||
if (variable_type == expected_type) {
|
||||
return variable;
|
||||
@@ -453,6 +454,16 @@ mf::Variable *MultiFunctionProcedureOperation::convert_variable(mf::Variable *va
|
||||
const mf::MultiFunction *function = conversion_table.get_conversion_multi_function(
|
||||
variable_type, expected_type);
|
||||
|
||||
/* Conversion is not possible, return a default variable instead. */
|
||||
if (!function) {
|
||||
const mf::MultiFunction &constant_function =
|
||||
procedure_.construct_function<mf::CustomMF_GenericConstant>(
|
||||
expected_type.single_type(), expected_type.single_type().default_value(), false);
|
||||
mf::Variable *constant_variable = procedure_builder_.add_call<1>(constant_function)[0];
|
||||
implicit_variables_.append(constant_variable);
|
||||
return constant_variable;
|
||||
}
|
||||
|
||||
mf::Variable *converted_variable = procedure_builder_.add_call<1>(*function, {variable})[0];
|
||||
implicit_variables_.append(converted_variable);
|
||||
return converted_variable;
|
||||
|
||||
Reference in New Issue
Block a user