Skip to content

Commit

Permalink
Possible bugfix: Use insert not emplace fixes nvhpc + gcc9
Browse files Browse the repository at this point in the history
  • Loading branch information
ptheywood committed Apr 4, 2022
1 parent 70de900 commit 4117492
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/flamegpu/model/AgentDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ AgentFunctionDescription& AgentDescription::newRTCFunction(const std::string& fu
func_src_str.append(func_src);
}
auto rtn = std::shared_ptr<AgentFunctionData>(new AgentFunctionData(this->agent->shared_from_this(), function_name, func_src_str, in_type_name, out_type_name, code_func_name));
agent->functions.emplace(function_name, rtn);
agent->functions.insert({function_name, rtn}); // emplace causes nvhpc with gcc 9 to segfault
return *rtn->description;
} else {
THROW exception::InvalidAgentFunc("Runtime agent function('%s') is missing FLAMEGPU_AGENT_FUNCTION arguments e.g. (func_name, message_input_type, message_output_type), "
Expand Down

3 comments on commit 4117492

@Robadob
Copy link
Member

@Robadob Robadob commented on 4117492 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, my understanding is that either should be fine in that case.

@ptheywood
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this just fixes the segfault though with GCC 9 and nvhpc as the host compiler.
From the time I was originally debugging this, I think there's potentially some UB related to the use of shared_from_this but i'm a long way from being confident about it. I don't think I managed to reproduce it with a MWE though / ran out of time.
The pushes yesterday were just cleaning up the commits (and blocking swig building from source via nvhpc) rather than any new dev.

@Robadob
Copy link
Member

@Robadob Robadob commented on 4117492 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah DW, I just spotted all the emails about the individual commits in my inbox this morning and a few piqued my interest so had a look.

Please sign in to comment.