[GH-ISSUE #1046] Event handler not de-registered when WiFiManager destroyed #894

Closed
opened 2026-02-28 01:27:32 +03:00 by kerem · 8 comments
Owner

Originally created by @liebman on GitHub (May 4, 2020).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1046

ESP32 on the development branch. The WiFiManager object was destroyed much earlier. The event callback gets called and eventually crash.

github.com/tzapu/WiFiManager@293f705b0f/WiFiManager.cpp (L208-L211)

Exception Cause: Not found

0x400ecb8f: Print::printf(char const*, ...) at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.cpp:234
0x400014fd: ?? ??:0
0x4000150d: ?? ??:0
0x400ecb8f: Print::printf(char const*, ...) at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.cpp:234
0x400e5ee9: void WiFiManager::DEBUG_WM<char const*, unsigned char>(WiFiManager::wm_debuglevel_t, char const*, unsigned char) at /Users/chris.l/.pio-workspaces/MatrixClock-f51995dc94/libdeps/esp32_liebman/WifiManager/WiFiManager.cpp:2448
0x400e5fd2: WiFiManager::WiFiEvent(system_event_id_t, system_event_info_t) at /Users/chris.l/.pio-workspaces/MatrixClock-f51995dc94/libdeps/esp32_liebman/WifiManager/WiFiManager.cpp:2448
0x400e1f46: void std::_Mem_fn_base<void (WiFiManager::*)(system_event_id_t, system_event_info_t), true>::operator()<system_event_id_t, system_event_info_t, void>(WiFiManager*, system_event_id_t&&, system_event_info_t&&) const at /Users/chris.l/.pio-workspaces/MatrixClock-f51995dc94/libdeps/esp32_liebman/WifiManager/WiFiManager.cpp:2448
 (inlined by) void std::_Bind<std::_Mem_fn<void (WiFiManager::*)(system_event_id_t, system_event_info_t)> (WiFiManager*, std::_Placeholder<1>, std::_Placeholder<2>)>::__call<void, system_event_id_t&&, system_event_info_t&&, 0u, 1u, 2u>(std::tuple<system_event_id_t&&, system_event_info_t&&>&&, std::_Index_tuple<0u, 1u, 2u>) at /Users/chris.l/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/functional:1074
 (inlined by) void std::_Bind<std::_Mem_fn<void (WiFiManager::*)(system_event_id_t, system_event_info_t)> (WiFiManager*, std::_Placeholder<1>, std::_Placeholder<2>)>::operator()<system_event_id_t, system_event_info_t, void>(system_event_id_t&&, system_event_info_t&&) at /Users/chris.l/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/functional:1133
 (inlined by) std::_Function_handler<void (system_event_id_t, system_event_info_t), std::_Bind<std::_Mem_fn<void (WiFiManager::*)(system_event_id_t, system_event_info_t)> (WiFiManager*, std::_Placeholder<1>, std::_Placeholder<2>)> >::_M_invoke(std::_Any_data const&, system_event_id_t&&, system_event_info_t&&) at /Users/chris.l/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/functional:1871
0x400da8c5: std::function<void (system_event_id_t, system_event_info_t)>::operator()(system_event_id_t, system_event_info_t) const at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.cpp:250
 (inlined by) WiFiGenericClass::_eventCallback(void*, system_event_t*) at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.cpp:438
0x400da965: _network_event_task(void*) at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.cpp:250
0x40088bfd: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)
Originally created by @liebman on GitHub (May 4, 2020). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1046 ESP32 on the development branch. The WiFiManager object was destroyed much earlier. The event callback gets called and eventually crash. https://github.com/tzapu/WiFiManager/blob/293f705b0ff29f5c78443a1f181a9872875aeac6/WiFiManager.cpp#L208-L211 ``` Exception Cause: Not found 0x400ecb8f: Print::printf(char const*, ...) at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.cpp:234 0x400014fd: ?? ??:0 0x4000150d: ?? ??:0 0x400ecb8f: Print::printf(char const*, ...) at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.cpp:234 0x400e5ee9: void WiFiManager::DEBUG_WM<char const*, unsigned char>(WiFiManager::wm_debuglevel_t, char const*, unsigned char) at /Users/chris.l/.pio-workspaces/MatrixClock-f51995dc94/libdeps/esp32_liebman/WifiManager/WiFiManager.cpp:2448 0x400e5fd2: WiFiManager::WiFiEvent(system_event_id_t, system_event_info_t) at /Users/chris.l/.pio-workspaces/MatrixClock-f51995dc94/libdeps/esp32_liebman/WifiManager/WiFiManager.cpp:2448 0x400e1f46: void std::_Mem_fn_base<void (WiFiManager::*)(system_event_id_t, system_event_info_t), true>::operator()<system_event_id_t, system_event_info_t, void>(WiFiManager*, system_event_id_t&&, system_event_info_t&&) const at /Users/chris.l/.pio-workspaces/MatrixClock-f51995dc94/libdeps/esp32_liebman/WifiManager/WiFiManager.cpp:2448 (inlined by) void std::_Bind<std::_Mem_fn<void (WiFiManager::*)(system_event_id_t, system_event_info_t)> (WiFiManager*, std::_Placeholder<1>, std::_Placeholder<2>)>::__call<void, system_event_id_t&&, system_event_info_t&&, 0u, 1u, 2u>(std::tuple<system_event_id_t&&, system_event_info_t&&>&&, std::_Index_tuple<0u, 1u, 2u>) at /Users/chris.l/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/functional:1074 (inlined by) void std::_Bind<std::_Mem_fn<void (WiFiManager::*)(system_event_id_t, system_event_info_t)> (WiFiManager*, std::_Placeholder<1>, std::_Placeholder<2>)>::operator()<system_event_id_t, system_event_info_t, void>(system_event_id_t&&, system_event_info_t&&) at /Users/chris.l/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/functional:1133 (inlined by) std::_Function_handler<void (system_event_id_t, system_event_info_t), std::_Bind<std::_Mem_fn<void (WiFiManager::*)(system_event_id_t, system_event_info_t)> (WiFiManager*, std::_Placeholder<1>, std::_Placeholder<2>)> >::_M_invoke(std::_Any_data const&, system_event_id_t&&, system_event_info_t&&) at /Users/chris.l/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/include/c++/5.2.0/functional:1871 0x400da8c5: std::function<void (system_event_id_t, system_event_info_t)>::operator()(system_event_id_t, system_event_info_t) const at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.cpp:250 (inlined by) WiFiGenericClass::_eventCallback(void*, system_event_t*) at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.cpp:438 0x400da965: _network_event_task(void*) at /Users/chris.l/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiGeneric.cpp:250 0x40088bfd: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1) ```
kerem 2026-02-28 01:27:32 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@tablatronix commented on GitHub (May 4, 2020):

haha

<!-- gh-comment-id:623701422 --> @tablatronix commented on GitHub (May 4, 2020): haha
Author
Owner

@tablatronix commented on GitHub (May 11, 2020):

Do you know which event, I am having a hard time reproducing to make sure a fix is working.

What does your code look like ?

<!-- gh-comment-id:626908095 --> @tablatronix commented on GitHub (May 11, 2020): Do you know which event, I am having a hard time reproducing to make sure a fix is working. What does your code look like ?
Author
Owner

@liebman commented on GitHub (May 11, 2020):

Hmm - don't know, but my guess would be something that happens at DHCP renew maybe? It was hours after the WiFiManager was destroyed. My code is changed to work around it by not creating a WiFiManager unless I need to config. Than reset after the config. If I get some time next weekend I'll try to reproduce it again and find the event. In any case I also saw that the core has no way of removing event handlers passed in as std::functions :-(

<!-- gh-comment-id:626995876 --> @liebman commented on GitHub (May 11, 2020): Hmm - don't know, but my guess would be something that happens at DHCP renew maybe? It was hours after the WiFiManager was destroyed. My code is changed to work around it by not creating a WiFiManager unless I need to config. Than reset after the config. If I get some time next weekend I'll try to reproduce it again and find the event. In any case I also saw that the core has no way of removing event handlers passed in as std::functions :-(
Author
Owner

@tablatronix commented on GitHub (May 11, 2020):

were you up to date because there is a flag in the event handler to avoid this..
odd

<!-- gh-comment-id:626997787 --> @tablatronix commented on GitHub (May 11, 2020): were you up to date because there is a flag in the event handler to avoid this.. odd
Author
Owner

@tablatronix commented on GitHub (May 11, 2020):

Well I added an event id, not sure if I need to protect its memory or not.. let me know if it fixes your problem.

<!-- gh-comment-id:626998680 --> @tablatronix commented on GitHub (May 11, 2020): Well I added an event id, not sure if I need to protect its memory or not.. let me know if it fixes your problem.
Author
Owner

@liebman commented on GitHub (May 11, 2020):

If your talking about _hasBegun that won't help once the WiFiManger object has been destroyed (and memory returned to heap or stack)...... It would see some random value. That would only work if its static.....

<!-- gh-comment-id:626999956 --> @liebman commented on GitHub (May 11, 2020): If your talking about `_hasBegun` that won't help once the WiFiManger object has been destroyed (and memory returned to heap or stack)...... It would see some random value. That would only work if its static.....
Author
Owner

@liebman commented on GitHub (May 11, 2020):

I'll give your update a try this weekend.

<!-- gh-comment-id:627001462 --> @liebman commented on GitHub (May 11, 2020): I'll give your update a try this weekend.
Author
Owner

@tablatronix commented on GitHub (May 11, 2020):

oh your right its not static, hmm I think I just reused it, it was for something else originally oops.

well this should take care of it, I think

<!-- gh-comment-id:627013535 --> @tablatronix commented on GitHub (May 11, 2020): oh your right its not static, hmm I think I just reused it, it was for something else originally oops. well this should take care of it, I think
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#894
No description provided.