Fix: assert when converting between incompatible field types

This results in a compile time error now which hopefully prevents
this specific kind of mistake in the future.
This commit is contained in:
Jacques Lucke 2023-01-28 14:52:15 +01:00
parent 89aae4ac82
commit 904357d67a
2 changed files with 11 additions and 1 deletions

View File

@ -193,6 +193,16 @@ template<typename T> class Field : public GField, detail::TypedFieldBase {
BLI_assert(this->cpp_type().template is<T>());
}
/**
* Generally, the constructor above would be sufficient, but this additional constructor ensures
* that trying to create e.g. a `Field<int>` from a `Field<float>` does not compile (instead of
* only failing at run-time).
*/
template<typename U> Field(Field<U> field) : GField(std::move(field))
{
static_assert(std::is_same_v<T, U>);
}
Field(std::shared_ptr<FieldNode> node, const int node_output_index = 0)
: Field(GField(std::move(node), node_output_index))
{

View File

@ -237,7 +237,7 @@ static void node_geo_exec(GeoNodeExecParams params)
}
if (params.output_is_required("Point Index")) {
Field<int> sort_index = params.extract_input<Field<int>>("Sort Index");
Field<int> sort_weight = params.extract_input<Field<float>>("Weights");
Field<float> sort_weight = params.extract_input<Field<float>>("Weights");
if (use_start_point_special_case(curve_index, sort_index, sort_weight)) {
params.set_output("Point Index", Field<int>(std::make_shared<CurveStartPointInput>()));
}