From b39ab9e4cea5790f8f2cfdc26f3ccf9ec03bbf82 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 27 Oct 2021 21:12:01 -0400 Subject: [PATCH] Check pointers in menu item helpers. --- include/helpers.hpp | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 38aa1589..e2b59a58 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -169,31 +169,31 @@ TParamWidget* createLightParamCentered(math::Vec pos, engine::Module* module, in template TMenu* createMenu() { - TMenu* o = new TMenu; - o->box.pos = APP->scene->mousePos; + TMenu* menu = new TMenu; + menu->box.pos = APP->scene->mousePos; ui::MenuOverlay* menuOverlay = new ui::MenuOverlay; - menuOverlay->addChild(o); + menuOverlay->addChild(menu); APP->scene->addChild(menuOverlay); - return o; + return menu; } template TMenuLabel* createMenuLabel(std::string text) { - TMenuLabel* o = new TMenuLabel; - o->text = text; - return o; + TMenuLabel* label = new TMenuLabel; + label->text = text; + return label; } template TMenuItem* createMenuItem(std::string text, std::string rightText = "") { - TMenuItem* o = new TMenuItem; - o->text = text; - o->rightText = rightText; - return o; + TMenuItem* item = new TMenuItem; + item->text = text; + item->rightText = rightText; + return item; } @@ -327,8 +327,13 @@ Example: template ui::MenuItem* createBoolPtrMenuItem(std::string text, std::string rightText, T* ptr) { return createBoolMenuItem(text, rightText, - [=]() {return *ptr;}, - [=](T val) {*ptr = val;} + [=]() { + return ptr ? *ptr : false; + }, + [=](T val) { + if (ptr) + *ptr = val; + } ); } @@ -442,8 +447,13 @@ Example: template ui::MenuItem* createIndexPtrSubmenuItem(std::string text, std::vector labels, T* ptr) { return createIndexSubmenuItem(text, labels, - [=]() {return *ptr;}, - [=](size_t index) {*ptr = T(index);} + [=]() { + return ptr ? *ptr : 0; + }, + [=](size_t index) { + if (ptr) + *ptr = T(index); + } ); }