From bc1a1c68769e68a3463258004e7b326e3f9fb9ae Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 16 Jan 2024 17:48:43 -0600 Subject: [PATCH] Fix more dynamic pointer strict casts to parent components (when they shouldn't be). Fixed double updating bug for components in ScrollableWindowComponents. --- Adventures in Lestoria/Menu.cpp | 8 ++++++-- Adventures in Lestoria/MenuComponent.cpp | 4 ++-- Adventures in Lestoria/ScrollableWindowComponent.h | 4 +++- Adventures in Lestoria/Version.h | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index a2cff2ed..a414790a 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -239,10 +239,14 @@ void Menu::Update(AiL*game){ } for(auto&[key,component]:components){ - component->_BeforeUpdate(game); + if(component->renderInMain){ + component->_BeforeUpdate(game); + } } for(auto&[key,component]:components){ - component->_Update(game); + if(component->renderInMain){ + component->_Update(game); + } } }; diff --git a/Adventures in Lestoria/MenuComponent.cpp b/Adventures in Lestoria/MenuComponent.cpp index a174567a..0468caa9 100644 --- a/Adventures in Lestoria/MenuComponent.cpp +++ b/Adventures in Lestoria/MenuComponent.cpp @@ -212,7 +212,7 @@ void MenuComponent::_OnMouseOut(){ if(runHoverFunctions){ if(hoverState){ hoverState=false; - onMouseOut(MenuFuncData{*Menu::menus[parentMenu],game,std::make_shared(*this),DYNAMIC_POINTER_CAST(parentComponent.lock())}); + onMouseOut(MenuFuncData{*Menu::menus[parentMenu],game,std::make_shared(*this),dynamic_pointer_cast(parentComponent.lock())}); OnMouseOut(); } } @@ -222,7 +222,7 @@ void MenuComponent::_OnHover(){ if(hovered){ if(runHoverFunctions&&!hoverState){ hoverState=true; - onHover(MenuFuncData{*Menu::menus[parentMenu],game,std::make_shared(*this),DYNAMIC_POINTER_CAST(parentComponent.lock())}); + onHover(MenuFuncData{*Menu::menus[parentMenu],game,std::make_shared(*this),dynamic_pointer_cast(parentComponent.lock())}); OnHover(); } } diff --git a/Adventures in Lestoria/ScrollableWindowComponent.h b/Adventures in Lestoria/ScrollableWindowComponent.h index b8d11a05..977118e3 100644 --- a/Adventures in Lestoria/ScrollableWindowComponent.h +++ b/Adventures in Lestoria/ScrollableWindowComponent.h @@ -106,7 +106,9 @@ protected: virtual inline void BeforeUpdate(AiL*game)override{ MenuComponent::BeforeUpdate(game); for(std::weak_ptrcomponent:components){ - component.lock()->_BeforeUpdate(game); + std::shared_ptrcomponentPtr=component.lock(); + if(componentPtr->renderInMain)ERR(std::format("WARNING! Component {} is inside a ScrollableWindowComponent but renders in main instead! Parent Component: {}",componentPtr->GetName(),GetName())); + componentPtr->_BeforeUpdate(game); } } virtual inline void Update(AiL*game)override{ diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index fcd8522e..73e4191e 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 5947 +#define VERSION_BUILD 5950 #define stringify(a) stringify_(a) #define stringify_(a) #a