From debced946edcfe6c4c4a9215c41f2be5cf49d795 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 23 Oct 2023 00:05:30 -0500 Subject: [PATCH] Menu component leak debugging detection added. --- Crawler/Menu.cpp | 11 ++++++++++- Crawler/Menu.h | 4 ++++ Crawler/MenuComponent.cpp | 4 ++-- Crawler/MenuComponent.h | 1 + Crawler/Version.h | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index 1c152b17..d275580c 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -14,6 +14,8 @@ safeunorderedmapMenu::themes; safemap>Menu::inventoryListeners; const vf2d Menu::CENTERED = {-456,-456}; std::vectorMenu::unhandledComponents; +MenuType Menu::lastMenuTypeCreated; +std::string Menu::lastRegisteredComponent; INCLUDE_GFX extern vi2d WINDOW_SIZE; @@ -61,7 +63,8 @@ void Menu::InitializeMenus(){ int count=0; for(MenuComponent*component:Menu::unhandledComponents){ std::cout<<"\tComponent "<<(count+1)<<": "<name<parentMenu<<" Label: "<label<memoryLeakInfo.first<<" // Last Component: "<memoryLeakInfo.second<Menu::GetMemoryLeakReportInfo(){ + return {lastMenuTypeCreated,lastRegisteredComponent}; } \ No newline at end of file diff --git a/Crawler/Menu.h b/Crawler/Menu.h index 59934711..f2c3da87 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -62,8 +62,12 @@ public: static void InventorySlotsUpdated(ITCategory cat); //Called whenever an inventory item gets added to the player's inventory, thus increasing the total number of slots in our bag. static void AddInventoryListener(MenuComponent*component,ITCategory category); //Adds a component to be in a given listener category. vf2d center(); + //Returns the last menu type created and last registered component, in case a component is detected as memory leaking, provides this information to each component for safety. + static std::pairGetMemoryLeakReportInfo(); private: Menu(vf2d pos,vf2d size); + static MenuType lastMenuTypeCreated; + static std::string lastRegisteredComponent; void HoverMenuSelect(Crawler*game); void MenuSelect(Crawler*game); void CheckClickAndPerformMenuSelect(Crawler*game); diff --git a/Crawler/MenuComponent.cpp b/Crawler/MenuComponent.cpp index 82e4129f..f479dad6 100644 --- a/Crawler/MenuComponent.cpp +++ b/Crawler/MenuComponent.cpp @@ -4,14 +4,14 @@ typedef Attribute A; MenuComponent::MenuComponent(MenuType parent,geom2d::rectrect,std::string label,MenuFunc onClick,bool selectable,bool selectableViaKeyboard) - :parentMenu(parent),rect(rect),label(label),menuDest(MenuType::ENUM_END),onClick(onClick),hoverEffect(0),selectable(selectable),selectableViaKeyboard(selectableViaKeyboard){ + :parentMenu(parent),rect(rect),label(label),menuDest(MenuType::ENUM_END),onClick(onClick),hoverEffect(0),selectable(selectable),selectableViaKeyboard(selectableViaKeyboard),memoryLeakInfo(Menu::GetMemoryLeakReportInfo()){ Menu::unhandledComponents.push_back(this); } MenuComponent::MenuComponent(MenuType parent,geom2d::rectrect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable,bool selectableViaKeyboard) :MenuComponent(parent,rect,label,onClick,selectable,selectableViaKeyboard){ + //NOTE: This constructor also calls the other constructor above! this->menuDest=menuDest; - Menu::unhandledComponents.push_back(this); } MenuComponent::~MenuComponent(){ diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index 76687c0c..2a5755bc 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -12,6 +12,7 @@ private: virtual bool GetHoverState(Crawler*game); //CALL THIS FOR A PARENT to check a child's DrawDecal validity! virtual bool PointWithinParent(MenuComponent*child,vi2d drawPos); + std::pairmemoryLeakInfo; //Used to identify memory leak hints for this component. protected: std::string name=""; geom2d::rectrect; diff --git a/Crawler/Version.h b/Crawler/Version.h index c7639ece..0d7fec4b 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 2329 +#define VERSION_BUILD 2335 #define stringify(a) stringify_(a) #define stringify_(a) #a