Fix #106002: Consider type when choosing switching type #106006

Merged
Jacques Lucke merged 2 commits from mod_moder/blender:fix_switch_crash into main 2023-03-22 17:54:38 +01:00
1 changed files with 6 additions and 1 deletions

View File

@ -145,11 +145,16 @@ static void node_gather_link_searches(GatherLinkSearchOpParams &params)
}
class LazyFunctionForSwitchNode : public LazyFunction {
private:
bool can_be_field_ = false;
public:
LazyFunctionForSwitchNode(const bNode &node)
{
const NodeSwitch &storage = node_storage(node);
const eNodeSocketDatatype data_type = eNodeSocketDatatype(storage.input_type);
can_be_field_ = ELEM(data_type, SOCK_FLOAT, SOCK_INT, SOCK_BOOLEAN, SOCK_VECTOR, SOCK_RGBA);
mod_moder marked this conversation as resolved Outdated

Can be simplified to can_be_field_ = ELEM(....)

Can be simplified to `can_be_field_ = ELEM(....)`
const bNodeSocketType *socket_type = nullptr;
for (const bNodeSocket *socket : node.output_sockets()) {
if (socket->type == data_type) {
@ -169,7 +174,7 @@ class LazyFunctionForSwitchNode : public LazyFunction {
void execute_impl(lf::Params &params, const lf::Context & /*context*/) const override
{
const ValueOrField<bool> condition = params.get_input<ValueOrField<bool>>(0);
if (condition.is_field()) {
if (condition.is_field() && can_be_field_) {
Field<bool> condition_field = condition.as_field();
if (condition_field.node().depends_on_input()) {
this->execute_field(condition.as_field(), params);