Use IF_SCREEN macro to guard against null screen object

This commit is contained in:
Jonathan Bennett
2025-12-28 11:33:14 -06:00
parent 759a972f77
commit 63aadba526
2 changed files with 17 additions and 20 deletions
+3 -5
View File
@@ -195,15 +195,13 @@ void MeshService::handleToRadio(meshtastic_MeshPacket &p)
p.rx_time = getValidTime(RTCQualityFromNet); // Record the time the packet arrived from the phone p.rx_time = getValidTime(RTCQualityFromNet); // Record the time the packet arrived from the phone
#if HAS_SCREEN IF_SCREEN(if (p.decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP && p.decoded.payload.size > 0 &&
if (p.decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP && p.decoded.payload.size > 0 && p.to != NODENUM_BROADCAST && p.to != NODENUM_BROADCAST && p.to != 0) // DM only
p.to != 0) // DM only
{ {
perhapsDecode(&p); perhapsDecode(&p);
const StoredMessage &sm = messageStore.addFromPacket(p); const StoredMessage &sm = messageStore.addFromPacket(p);
graphics::MessageRenderer::handleNewMessage(nullptr, sm, p); // notify UI graphics::MessageRenderer::handleNewMessage(nullptr, sm, p); // notify UI
} })
#endif
// Send the packet into the mesh // Send the packet into the mesh
DEBUG_HEAP_BEFORE; DEBUG_HEAP_BEFORE;
auto a = packetPool.allocCopy(p); auto a = packetPool.allocCopy(p);
+3 -4
View File
@@ -21,8 +21,8 @@ ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp
// We only store/display messages destined for us. // We only store/display messages destined for us.
devicestate.rx_text_message = mp; devicestate.rx_text_message = mp;
devicestate.has_rx_text_message = true; devicestate.has_rx_text_message = true;
#if HAS_SCREEN IF_SCREEN(
// Guard against running in MeshtasticUI // Guard against running in MeshtasticUI or with no screen
if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) { if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) {
// Store in the central message history // Store in the central message history
const StoredMessage &sm = messageStore.addFromPacket(mp); const StoredMessage &sm = messageStore.addFromPacket(mp);
@@ -31,8 +31,7 @@ ProcessMessage TextMessageModule::handleReceived(const meshtastic_MeshPacket &mp
// Use the global Screen singleton to retrieve the current OLED display // Use the global Screen singleton to retrieve the current OLED display
auto *display = screen ? screen->getDisplayDevice() : nullptr; auto *display = screen ? screen->getDisplayDevice() : nullptr;
graphics::MessageRenderer::handleNewMessage(display, sm, mp); graphics::MessageRenderer::handleNewMessage(display, sm, mp);
} })
#endif
// Only trigger screen wake if configuration allows it // Only trigger screen wake if configuration allows it
if (shouldWakeOnReceivedMessage()) { if (shouldWakeOnReceivedMessage()) {
powerFSM.trigger(EVENT_RECEIVED_MSG); powerFSM.trigger(EVENT_RECEIVED_MSG);