From a67b85eabf4f584ef4a7d136bee5f04421d8defe Mon Sep 17 00:00:00 2001 From: Samuel Sieb Date: Sat, 15 Feb 2025 23:02:51 -0800 Subject: [PATCH] don't crash on null pages (#8254) Co-authored-by: Samuel Sieb --- esphome/components/display/display.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/esphome/components/display/display.cpp b/esphome/components/display/display.cpp index 202c64ef14..b12a81e050 100644 --- a/esphome/components/display/display.cpp +++ b/esphome/components/display/display.cpp @@ -815,8 +815,20 @@ void Display::test_card() { DisplayPage::DisplayPage(display_writer_t writer) : writer_(std::move(writer)) {} void DisplayPage::show() { this->parent_->show_page(this); } -void DisplayPage::show_next() { this->next_->show(); } -void DisplayPage::show_prev() { this->prev_->show(); } +void DisplayPage::show_next() { + if (this->next_ == nullptr) { + ESP_LOGE(TAG, "no next page"); + return; + } + this->next_->show(); +} +void DisplayPage::show_prev() { + if (this->prev_ == nullptr) { + ESP_LOGE(TAG, "no previous page"); + return; + } + this->prev_->show(); +} void DisplayPage::set_parent(Display *parent) { this->parent_ = parent; } void DisplayPage::set_prev(DisplayPage *prev) { this->prev_ = prev; } void DisplayPage::set_next(DisplayPage *next) { this->next_ = next; }