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:
James Devine 2016-01-13 14:15:50 +00:00
parent d2df88417b
commit 8d3f3affbd
2 changed files with 12 additions and 0 deletions

View File

@ -96,6 +96,10 @@ class MicroBitButton : public MicroBitComponent
*/ */
virtual void systemTick(); virtual void systemTick();
/**
* Destructor for MicroBitButton, so that we deregister ourselves as a systemComponent
*/
~MicroBitButton();
}; };
#endif #endif

View File

@ -100,3 +100,11 @@ int MicroBitButton::isPressed()
{ {
return status & MICROBIT_BUTTON_STATE ? 1 : 0; return status & MICROBIT_BUTTON_STATE ? 1 : 0;
} }
/**
* Destructor for MicroBitButton, so that we deregister ourselves as a systemComponent
*/
MicroBitButton::~MicroBitButton()
{
uBit.removeSystemComponent(this);
}