diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 7737ac4..2bc8a6d 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -325,8 +325,7 @@ void GMenu2X::initBG() { drawTopBar(*bg); drawBottomBar(*bg); - Surface *bgmain = new Surface(bg); - sc.add(bgmain,"bgmain"); + Surface *bgmain = sc.add(bg, "bgmain"); Surface *sd = Surface::loadImage("imgs/sd.png", confStr["skin"]); if (sd) sd->blit(*bgmain, 3, bottomBarIconY); diff --git a/src/surfacecollection.cpp b/src/surfacecollection.cpp index ef120c4..9c51626 100644 --- a/src/surfacecollection.cpp +++ b/src/surfacecollection.cpp @@ -98,10 +98,11 @@ bool SurfaceCollection::exists(const string &path) { return surfaces.find(path) != surfaces.end(); } -Surface *SurfaceCollection::add(Surface *s, const string &path) { +Surface *SurfaceCollection::add(Surface const& s, std::string const& path) { if (exists(path)) del(path); - surfaces[path] = s; - return s; + Surface *copy = new Surface(s); + surfaces[path] = copy; + return copy; } Surface *SurfaceCollection::add(const string &path) { diff --git a/src/surfacecollection.h b/src/surfacecollection.h index 631125f..10165e1 100644 --- a/src/surfacecollection.h +++ b/src/surfacecollection.h @@ -45,7 +45,12 @@ public: bool defaultAlpha = true; void debug(); - Surface *add(Surface *s, const std::string &path); + /** + * Adds a copy of the given surface to this collection under the given + * path. Returns the copy. + */ + Surface *add(Surface const& s, std::string const& path); + Surface *add(const std::string &path); Surface *addSkinRes(const std::string &path, bool useDefault = true); void del(const std::string &path);