Fix T99316: Crash with no font in String to Curves node
If you remove the default font from the project, the node will not have the selected font. In this case, there is no check that the font does not exist. This suggestion adds an error message if the font is not specified. Differential Revision: https://developer.blender.org/D15337
This commit is contained in:
parent
ab444a80a2
commit
4ffee9a48d
Notes:
blender-bot
2023-02-14 05:25:44 +01:00
Referenced by issue #99316, Crash when no font is in String to Curves in geometry nodes
|
@ -157,12 +157,18 @@ struct TextLayout {
|
|||
float final_font_size;
|
||||
};
|
||||
|
||||
static TextLayout get_text_layout(GeoNodeExecParams ¶ms)
|
||||
static std::optional<TextLayout> get_text_layout(GeoNodeExecParams ¶ms)
|
||||
{
|
||||
VFont *vfont = reinterpret_cast<VFont *>(params.node().id);
|
||||
if (!vfont) {
|
||||
params.error_message_add(NodeWarningType::Error, TIP_("Font not specified"));
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
TextLayout layout;
|
||||
layout.text = params.extract_input<std::string>("String");
|
||||
if (layout.text.empty()) {
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const NodeGeometryStringToCurves &storage = node_storage(params.node());
|
||||
|
@ -181,7 +187,6 @@ static TextLayout get_text_layout(GeoNodeExecParams ¶ms)
|
|||
const float textbox_h = overflow == GEO_NODE_STRING_TO_CURVES_MODE_OVERFLOW ?
|
||||
0.0f :
|
||||
params.extract_input<float>("Text Box Height");
|
||||
VFont *vfont = (VFont *)params.node().id;
|
||||
|
||||
Curve cu = dna::shallow_zero_initialize();
|
||||
cu.type = OB_FONT;
|
||||
|
@ -361,15 +366,19 @@ static void create_attributes(GeoNodeExecParams ¶ms,
|
|||
|
||||
static void node_geo_exec(GeoNodeExecParams params)
|
||||
{
|
||||
TextLayout layout = get_text_layout(params);
|
||||
std::optional<TextLayout> layout = get_text_layout(params);
|
||||
if (!layout) {
|
||||
params.set_default_remaining_outputs();
|
||||
return;
|
||||
}
|
||||
|
||||
const NodeGeometryStringToCurves &storage =
|
||||
*(const NodeGeometryStringToCurves *)params.node().storage;
|
||||
if (storage.overflow == GEO_NODE_STRING_TO_CURVES_MODE_TRUNCATE) {
|
||||
params.set_output("Remainder", std::move(layout.truncated_text));
|
||||
params.set_output("Remainder", std::move(layout->truncated_text));
|
||||
}
|
||||
|
||||
if (layout.positions.size() == 0) {
|
||||
if (layout->positions.size() == 0) {
|
||||
params.set_output("Curve Instances", GeometrySet());
|
||||
params.set_default_remaining_outputs();
|
||||
return;
|
||||
|
@ -378,9 +387,9 @@ static void node_geo_exec(GeoNodeExecParams params)
|
|||
/* Create and add instances. */
|
||||
GeometrySet geometry_set_out;
|
||||
InstancesComponent &instances = geometry_set_out.get_component_for_write<InstancesComponent>();
|
||||
Map<int, int> char_handles = create_curve_instances(params, layout, instances);
|
||||
add_instances_from_handles(instances, char_handles, layout);
|
||||
create_attributes(params, layout, instances);
|
||||
Map<int, int> char_handles = create_curve_instances(params, *layout, instances);
|
||||
add_instances_from_handles(instances, char_handles, *layout);
|
||||
create_attributes(params, *layout, instances);
|
||||
|
||||
params.set_output("Curve Instances", std::move(geometry_set_out));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue