Skip to content

Commit

Permalink
Fix access to deleted dashboard
Browse files Browse the repository at this point in the history
Use shared_ptr instead of raw pointers.
  • Loading branch information
frankosterfeld committed Oct 1, 2024
1 parent 750ce03 commit 0c643ea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ui/Dashboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Dashboard : public std::enable_shared_from_this<Dashboard> {
inline auto& plots() { return m_plots; }

void setNewDescription(const std::shared_ptr<DashboardDescription>& desc);
inline DashboardDescription* description() const { return m_desc.get(); }
inline std::shared_ptr<DashboardDescription> description() const { return m_desc; }

struct Service {
Service(std::string n, std::string u) : name(std::move(n)), uri(std::move(u)) {}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/OpenDashboardPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void OpenDashboardPage::unsubscribeSource(const std::shared_ptr<DashboardSource>
static constexpr float indent = 20;

//
void OpenDashboardPage::dashboardControls(Dashboard* optionalDashboard) {
void OpenDashboardPage::dashboardControls(const std::shared_ptr<Dashboard>& optionalDashboard) {
IMW::Font titleFont(LookAndFeel::instance().fontBigger[LookAndFeel::instance().prototypeMode]);

if (optionalDashboard) {
Expand Down Expand Up @@ -144,7 +144,7 @@ void OpenDashboardPage::dashboardControls(Dashboard* optionalDashboard) {
}
}

void OpenDashboardPage::draw(Dashboard* optionalDashboard) {
void OpenDashboardPage::draw(const std::shared_ptr<Dashboard>& optionalDashboard) {
ImGui::Spacing();

dashboardControls(optionalDashboard);
Expand Down Expand Up @@ -292,7 +292,7 @@ void OpenDashboardPage::draw(Dashboard* optionalDashboard) {

const auto& name = item.first->name;
const auto& source = item.first->source;
bool isDashboardActive = optionalDashboard && name == optionalDashboard->description()->name && source == optionalDashboard->description()->source;
bool isDashboardActive = optionalDashboard && optionalDashboard->description() && name == optionalDashboard->description()->name && source == optionalDashboard->description()->source;

{
IMW::Font font(isDashboardActive ? LookAndFeel::instance().fontIconsSolid : LookAndFeel::instance().fontIcons);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/OpenDashboardPage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class OpenDashboardPage {
std::function<void()> requestCloseDashboard;
std::function<void(const std::shared_ptr<DashboardDescription> &)> requestLoadDashboard;

void draw(Dashboard *optionalDashboard);
void draw(const std::shared_ptr<Dashboard>& optionalDashboard);

void addSource(std::string_view path);
void addDashboard(const std::shared_ptr<DashboardSource> &source, const auto &n);

std::shared_ptr<DashboardDescription> get(const size_t index);

private:
void dashboardControls(Dashboard *optionalDashboard);
void dashboardControls(const std::shared_ptr<Dashboard>& optionalDashboard);
void drawAddSourcePopup();
void unsubscribeSource(const std::shared_ptr<DashboardSource> &source);

Expand Down
2 changes: 1 addition & 1 deletion src/ui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static void main_loop(void* arg) {
}
}
} else if (app->mainViewMode == ViewMode::OPEN_SAVE_DASHBOARD) {
app->openDashboardPage.draw(app->dashboard.get());
app->openDashboardPage.draw(app->dashboard);
} else {
fmt::print("unknown view mode {}\n", static_cast<int>(app->mainViewMode));
}
Expand Down

0 comments on commit 0c643ea

Please sign in to comment.