Menu component leak debugging detection added.
This commit is contained in:
parent
800a5767f2
commit
debced946e
@ -14,6 +14,8 @@ safeunorderedmap<std::string,Theme>Menu::themes;
|
||||
safemap<ITCategory,std::vector<MenuComponent*>>Menu::inventoryListeners;
|
||||
const vf2d Menu::CENTERED = {-456,-456};
|
||||
std::vector<MenuComponent*>Menu::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)<<": "<<std::endl;
|
||||
std::cout<<"\t-"<<component->name<<std::endl;
|
||||
std::cout<<"\t-Parent Menu:"<<component->parentMenu<<" Label: "<<component->label<<std::endl;
|
||||
std::cout<<"\t\tCreated Inside of Menu: "<<component->memoryLeakInfo.first<<" // Last Component: "<<component->memoryLeakInfo.second<<std::endl;
|
||||
count++;
|
||||
}
|
||||
throw;
|
||||
@ -70,6 +73,7 @@ void Menu::InitializeMenus(){
|
||||
|
||||
Menu*Menu::CreateMenu(MenuType type,vf2d pos,vf2d size){
|
||||
menus[type]=new Menu(pos,size);
|
||||
lastMenuTypeCreated=type;
|
||||
return menus.at(type);
|
||||
}
|
||||
|
||||
@ -114,6 +118,7 @@ void Menu::AddComponent(std::string key,MenuComponent*button){
|
||||
components.Unlock(); //It's possible we can add a component later on, so we will make sure we remove the lock first.
|
||||
components[key]=button;
|
||||
components.SetInitialized();
|
||||
lastRegisteredComponent=key;
|
||||
std::erase_if(Menu::unhandledComponents,[&](MenuComponent*b1){return b1==button;});
|
||||
}
|
||||
|
||||
@ -619,3 +624,7 @@ void Menu::CloseMenu(){
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<MenuType,std::string>Menu::GetMemoryLeakReportInfo(){
|
||||
return {lastMenuTypeCreated,lastRegisteredComponent};
|
||||
}
|
@ -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::pair<MenuType,std::string>GetMemoryLeakReportInfo();
|
||||
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);
|
||||
|
@ -4,14 +4,14 @@
|
||||
typedef Attribute A;
|
||||
|
||||
MenuComponent::MenuComponent(MenuType parent,geom2d::rect<float>rect,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::rect<float>rect,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(){
|
||||
|
@ -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::pair<MenuType,std::string>memoryLeakInfo; //Used to identify memory leak hints for this component.
|
||||
protected:
|
||||
std::string name="";
|
||||
geom2d::rect<float>rect;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user