Index: ps/trunk/source/gui/CGUI.cpp =================================================================== --- ps/trunk/source/gui/CGUI.cpp +++ ps/trunk/source/gui/CGUI.cpp @@ -999,7 +999,8 @@ if (m_Sprites.find(name) != m_Sprites.end()) LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str()); - SGUIImageEffects* effects = NULL; + // shared_ptr to link the effect to every sprite, faster than copy. + std::shared_ptr effects; for (XMBElement child : Element.GetChildNodes()) { @@ -1013,7 +1014,7 @@ LOGERROR("GUI must not have more than one "); else { - effects = new SGUIImageEffects; + effects = std::make_shared(); Xeromyces_ReadEffects(child, pFile, *effects); } } @@ -1026,9 +1027,7 @@ if (effects) for (SGUIImage* const& img : Sprite->m_Images) if (!img->m_Effects) - img->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later - - delete effects; + img->m_Effects = effects; m_Sprites.erase(name); m_Sprites.emplace(name, Sprite); @@ -1157,7 +1156,7 @@ LOGERROR("GUI must not have more than one "); else { - Image->m_Effects = new SGUIImageEffects; + Image->m_Effects = std::make_shared(); Xeromyces_ReadEffects(child, pFile, *Image->m_Effects); } } Index: ps/trunk/source/gui/CGUISprite.h =================================================================== --- ps/trunk/source/gui/CGUISprite.h +++ ps/trunk/source/gui/CGUISprite.h @@ -41,6 +41,8 @@ #include "lib/res/graphics/ogl_tex.h" +#include + struct SGUIImageEffects { SGUIImageEffects() : m_Greyscale(false) {} @@ -59,13 +61,8 @@ public: SGUIImage() : m_FixedHAspectRatio(0.f), m_RoundCoordinates(true), m_WrapMode(GL_REPEAT), - m_Effects(NULL), m_Border(false), m_DeltaZ(0.f) - { - } - - ~SGUIImage() + m_Effects(), m_Border(false), m_DeltaZ(0.f) { - delete m_Effects; } // Filename of the texture @@ -106,7 +103,7 @@ GLint m_WrapMode; // Visual effects (e.g. color modulation) - SGUIImageEffects* m_Effects; + std::shared_ptr m_Effects; // Color CGUIColor m_BackColor; Index: ps/trunk/source/gui/GUIRenderer.cpp =================================================================== --- ps/trunk/source/gui/GUIRenderer.cpp +++ ps/trunk/source/gui/GUIRenderer.cpp @@ -106,7 +106,7 @@ // Allow grayscale images for disabled portraits if (SpriteName.Find("grayscale:") != -1) { - Image->m_Effects = new SGUIImageEffects; + Image->m_Effects = std::make_shared(); Image->m_Effects->m_Greyscale = true; } @@ -158,7 +158,7 @@ if (SpriteName.Find("textureAsMask:") != -1) { Image->m_TextureName = TextureName; - Image->m_Effects = new SGUIImageEffects; + Image->m_Effects = std::make_shared(); Image->m_Effects->m_SolidColor = color; } else