[Bf-blender-cvs] [904357d67a2] master: Fix: assert when converting between incompatible field types
Jacques Lucke
noreply at git.blender.org
Sat Jan 28 14:56:49 CET 2023
Commit: 904357d67a29ccc7fb512f22619288d2db182b9e
Author: Jacques Lucke
Date: Sat Jan 28 14:52:15 2023 +0100
Branches: master
https://developer.blender.org/rB904357d67a29ccc7fb512f22619288d2db182b9e
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.
===================================================================
M source/blender/functions/FN_field.hh
M source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
===================================================================
diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh
index 993558b3a18..7d1fa855206 100644
--- a/source/blender/functions/FN_field.hh
+++ b/source/blender/functions/FN_field.hh
@@ -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))
{
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
index 820fa4856a4..086a68401ed 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
@@ -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>()));
}
More information about the Bf-blender-cvs
mailing list