[color] do not use setValue() in SourceChoice / SwitchChoice

This potentially deletes the source/switch choice, which then triggers a "use-after-free".

Resolves #759
This commit is contained in:
Raphael Coeffic
2021-09-20 11:04:11 +10:00
committed by Peter Feerick
parent 66b523cf88
commit 64a87812bb
6 changed files with 11 additions and 18 deletions
+1 -1
View File
@@ -345,7 +345,7 @@ class ModelCategoryPageBody : public FormWindow
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y)
bool onTouchEnd(coord_t x, coord_t y) override
{
if(category->size() == 0)
addFirstModel();
+3 -9
View File
@@ -70,10 +70,7 @@ SourceChoice::SourceChoice(FormGroup *parent, const rect_t &rect, int16_t vmin,
menu->setWaitHandler([=]() {
int16_t val = getMovedSource(vmin);
if (val) {
if (setValue) {
setValue(val);
}
this->fillMenu(menu);
fillMenu(menu, val);
}
#if defined(AUTOSWITCH)
else {
@@ -81,8 +78,7 @@ SourceChoice::SourceChoice(FormGroup *parent, const rect_t &rect, int16_t vmin,
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
val = switchToMix(swtch);
if (val && (val >= vmin) && (val <= vmax)) {
if (setValue) setValue(val);
this->fillMenu(menu);
fillMenu(menu, val);
}
}
}
@@ -101,10 +97,8 @@ SourceChoice::SourceChoice(FormGroup *parent, const rect_t &rect, int16_t vmin,
setAvailableHandler([](int v){ return isSourceAvailable(v); });
}
void SourceChoice::fillMenu(Menu *menu,
const std::function<bool(int16_t)> &filter)
void SourceChoice::fillMenu(Menu *menu, int16_t value, const FilterFct& filter)
{
auto value = getValue();
int count = 0;
int current = 0;
+2 -2
View File
@@ -42,8 +42,8 @@ class SourceChoice : public ChoiceEx
#endif
protected:
void fillMenu(Menu* menu,
const std::function<bool(int16_t)>& condition = nullptr);
typedef std::function<bool(int16_t)> FilterFct;
void fillMenu(Menu* menu, int16_t value, const FilterFct& condition = nullptr);
};
#endif // _SOURCECHOICE_H_
+2 -4
View File
@@ -62,8 +62,7 @@ SwitchChoice::SwitchChoice(FormGroup* parent, const rect_t& rect, int vmin,
val = swtch;
}
if (val && (!isValueAvailable || isValueAvailable(val))) {
if (setValue) setValue(val);
this->fillMenu(menu);
fillMenu(menu, val);
}
}
});
@@ -88,9 +87,8 @@ SwitchChoice::SwitchChoice(FormGroup* parent, const rect_t& rect, int vmin,
setAvailableHandler(isSwitchAvailableInMixes);
}
void SwitchChoice::fillMenu(Menu* menu, std::function<bool(int16_t)> filter)
void SwitchChoice::fillMenu(Menu* menu, int16_t value, const FilterFct& filter)
{
auto value = getValue();
int count = 0;
int current = 0;
+2 -1
View File
@@ -38,7 +38,8 @@ class SwitchChoice : public ChoiceEx
#endif
protected:
void fillMenu(Menu* menu, std::function<bool(int16_t)> condition = nullptr);
typedef std::function<bool(int16_t)> FilterFct;
void fillMenu(Menu* menu, int16_t value, const FilterFct& filter = nullptr);
};
#endif // _SWITCHCHOICE_H_