You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue
If I create an Easybutton object as a global object, the libary works fine.
However, If I create it as a local object, it misbehaves badly:
The object sometimes performs callbacks to random adresses on the microcontrollers memory, when using EsayButton::read(), causign the programm to malfunction or crash.
This only happens sometimes and only if no callback function was used/specified.
Reason
I think I also found the issue causing this:
In EasyButtonBase.h, the callback function is specified like this:
class EasyButtonBase
{
...
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
callback_t _pressed_sequence_callbacks[MAX_SEQUENCES];
#endif
callback_t _pressed_callback; // Callback function for pressed events.
callback_t _pressed_for_callback; // Callback function for pressedFor events.
This results in the callbacks being initialized with 0 as the default value if being created as a global object. If created as a local object, they are not initialized and start with a random value.
In EasyButton.cpp it then checks if a callback is set by looking for non-zero values;
if (_pressed_callback)
{
_pressed_callback();
}
So If ther random starting value is not zero, this results in callbacks to random adresses.
Possible fix
Initialize the values properly:
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
callback_t _pressed_sequence_callbacks[MAX_SEQUENCES] ={0};
#endif
callback_t _pressed_callback = 0; // Callback function for pressed events.
callback_t _pressed_for_callback = 0; // Callback function for pressedFor events.
The text was updated successfully, but these errors were encountered:
I think I found a bug:
Issue
If I create an Easybutton object as a global object, the libary works fine.
However, If I create it as a local object, it misbehaves badly:
The object sometimes performs callbacks to random adresses on the microcontrollers memory, when using
EsayButton::read()
, causign the programm to malfunction or crash.This only happens sometimes and only if no callback function was used/specified.
Reason
I think I also found the issue causing this:
In EasyButtonBase.h, the callback function is specified like this:
This results in the callbacks being initialized with 0 as the default value if being created as a global object. If created as a local object, they are not initialized and start with a random value.
In EasyButton.cpp it then checks if a callback is set by looking for non-zero values;
So If ther random starting value is not zero, this results in callbacks to random adresses.
Possible fix
Initialize the values properly:
The text was updated successfully, but these errors were encountered: