microbit: fix for #73
The destructor for MicroBitButton didn't take into account the fact that an instance can be destructed after registering a callback. This would then result in a HardFault if an instance was destructed. A clear repro case was registering a Touch input on a pin (abstracted as a button) and swapping to a DigitalIn.
This commit is contained in:
parent
d2df88417b
commit
8d3f3affbd
2 changed files with 12 additions and 0 deletions
|
@ -96,6 +96,10 @@ class MicroBitButton : public MicroBitComponent
|
|||
*/
|
||||
virtual void systemTick();
|
||||
|
||||
/**
|
||||
* Destructor for MicroBitButton, so that we deregister ourselves as a systemComponent
|
||||
*/
|
||||
~MicroBitButton();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -100,3 +100,11 @@ int MicroBitButton::isPressed()
|
|||
{
|
||||
return status & MICROBIT_BUTTON_STATE ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor for MicroBitButton, so that we deregister ourselves as a systemComponent
|
||||
*/
|
||||
MicroBitButton::~MicroBitButton()
|
||||
{
|
||||
uBit.removeSystemComponent(this);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue