Skip to content

Commit

Permalink
BugFix: Graph visualisation would only work if CUDASimulation was exp…
Browse files Browse the repository at this point in the history
…licitly init()

It should now work if the simulation is not explicitly init, or is init before the visualiser is created.
  • Loading branch information
Robadob committed Oct 28, 2024
1 parent f3f6b0d commit 12e5582
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/flamegpu/simulation/CUDASimulation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,6 @@ void CUDASimulation::applyConfig_derived() {

// We init Random through submodel hierarchy after singletons
reseed(getSimulationConfig().random_seed);

#ifdef FLAMEGPU_VISUALISATION
if (visualisation) {
visualisation->hookVis(visualisation, directed_graph_map);
}
#endif
}

void CUDASimulation::reseed(const uint64_t seed) {
Expand Down Expand Up @@ -1662,6 +1656,12 @@ void CUDASimulation::initialiseSingletons() {

// Ensure RTC is set up.
initialiseRTC();

#ifdef FLAMEGPU_VISUALISATION
if (visualisation) {
visualisation->hookVis(visualisation, directed_graph_map);
}
#endif
}

void CUDASimulation::initialiseRTC() {
Expand Down Expand Up @@ -1717,6 +1717,10 @@ const CUDASimulation::Config &CUDASimulation::getCUDAConfig() const {
visualiser::ModelVis CUDASimulation::getVisualisation() {
if (!visualisation) {
visualisation = std::make_shared<visualiser::ModelVisData>(*this);
// If visualisation is init after sim has been init ensure graphs are linked to vis
if (directed_graph_map.size()) {
visualisation->hookVis(visualisation, directed_graph_map);
}
}
return visualiser::ModelVis(visualisation, isSWIG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,12 @@ void CUDAEnvironmentDirectedGraphBuffers::syncDevice_async(detail::CUDAScatter&
if (has_changed) {
#ifdef FLAMEGPU_VISUALISATION
if (auto vis = visualisation.lock()) {
vis->visualiser->lockDynamicLinesMutex();
vis->rebuildEnvGraph(graph_description.name);
vis->visualiser->updateDynamicLine(std::string("graph_") + graph_description.name);
vis->visualiser->releaseDynamicLinesMutex();
if (vis->graphs.find(graph_description.name) != vis->graphs.end()) {
vis->visualiser->lockDynamicLinesMutex();
vis->rebuildEnvGraph(graph_description.name);
vis->visualiser->updateDynamicLine(std::string("graph_") + graph_description.name);
vis->visualiser->releaseDynamicLinesMutex();
}
}
#endif
}
Expand Down
4 changes: 3 additions & 1 deletion src/flamegpu/visualiser/ModelVis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ ModelVisData::ModelVisData(const flamegpu::CUDASimulation &_model)
, modelData(_model.getModelDescription()) { }

void ModelVisData::hookVis(std::shared_ptr<visualiser::ModelVisData>& vis, std::unordered_map<std::string, std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers>> &map) {
for (auto [key, buf] : map) {
buf->setVisualisation(vis);
}
for (auto [name, graph] : graphs) {
auto &graph_buffs = map.at(name);
graph_buffs->setVisualisation(vis);
graph->constructGraph(graph_buffs);
vis->rebuildEnvGraph(name);
}
Expand Down

0 comments on commit 12e5582

Please sign in to comment.