Skip to content

Fix boot crash: guard ESP_LOG during static initialization#18

Open
psarossy wants to merge 1 commit intobullshit:mainfrom
psarossy:fix/static-init-crash
Open

Fix boot crash: guard ESP_LOG during static initialization#18
psarossy wants to merge 1 commit intobullshit:mainfrom
psarossy:fix/static-init-crash

Conversation

@psarossy
Copy link
Copy Markdown

Summary

  • Guard 3 ESP_LOG* calls in protocol_factory.cpp with global_logger != nullptr checks
  • These calls run during C++ static initialization (via REGISTER_UPS_* macros) before the ESPHome Logger is constructed
  • Without the guard, dereferencing the null logger pointer causes Guru Meditation Error: Core 0 panic'ed (LoadProhibited) at EXCVADDR: 0x0000002c on every boot

Root Cause

REGISTER_UPS_PROTOCOL_FOR_VENDOR / REGISTER_UPS_FALLBACK_PROTOCOL macros create file-scope static variables whose constructors call register_protocol_for_vendor()ensure_initialized()ESP_LOGD() during do_global_ctors, before main() runs.

Test plan

  • Tested on ESP32-S3-DevKitC-1 with ESPHome 2026.3.0 / ESP-IDF 5.5.3
  • Confirmed crash without fix, clean boot with fix
  • Logs still appear at runtime when called after Logger construction

Fixes #17

🤖 Generated with Claude Code

Protocol registration functions (register_protocol_for_vendor,
register_fallback_protocol, ensure_initialized) are called during C++
static initialization via REGISTER_UPS_PROTOCOL_FOR_VENDOR and
REGISTER_UPS_FALLBACK_PROTOCOL macros. At this point the ESPHome Logger
has not yet been constructed, so ESP_LOG* calls dereference a null
global_logger pointer, causing:

  Guru Meditation Error: Core 0 panic'ed (LoadProhibited)
  EXCVADDR: 0x0000002c

Guard all three ESP_LOG calls with a null check on global_logger so they
still log when called at runtime but are safely skipped during static init.

Fixes bullshit#17

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash on boot: static init order fiasco in ProtocolFactory + GoldenMate UPS parsing issues

1 participant