Closed Robadob closed 9 months ago
With the codegen from current master
@pyflamegpu.agent_function
def input_message(message_in: pyflamegpu.MessageArray, message_out: pyflamegpu.MessageNone):
interlocutor = pyflamegpu.random.uniformInt(0, 4)
msg = message_in.at(interlocutor - 1)
pyflamegpu.setVariableInt("var", msg.getVariableInt('var'))
return pyflamegpu.ALIVE
Translates to
FLAMEGPU_AGENT_FUNCTION(input_message, flamegpu::MessageArray, flamegpu::MessageNone){
auto interlocutor = FLAMEGPU->random.uniform<int>(0, 4);
auto msg = FLAMEGPU->message_in.at((interlocutor - 1));
FLAMEGPU->setVariable<int>("var", msg.getVariableInt("var"));
return flamegpu::ALIVE;
}
Hence the incorrect msg.getVariableInt("var")
.
Obvious bug would be that it only expects message methods inside a message loop when transpiling. Will require some investigation, possibly input from @mondus.
The doc comment of codegen.py::dispatchMemberFunction()
seems to confirm this has been overlooked, not immediately clear (to me) the best way to address it though. To do it properly would require some AST magic to track that msg
was returns by message_in.at()
.
Lazy option would just be to regex groups replace all instances of getVariableType, but could break some esoteric cases.
Discussed in https://github.com/FLAMEGPU/FLAMEGPU2/discussions/1109
Need to check whether this can be reproduced, but it appears array messages may be being processed wrong.