1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2025-04-21 12:27:27 +03:00

Surface: Load image with factory method instead of constructor.

If loading fails, the factory method returns NULL, while previously the
constructor would create a Surface object with a NULL "raw" field.
However, since most of the methods dereference "raw" without checking,
such a Surface would likely crash the application when used.
This commit is contained in:
Maarten ter Huurne
2011-06-02 22:09:03 +02:00
parent 0a9229ff3f
commit 52f4686e4a
5 changed files with 59 additions and 48 deletions

View File

@@ -80,8 +80,10 @@ Surface *SurfaceCollection::add(const string &path) {
return NULL;
} else if (!fileExists(filePath)) return NULL;
Surface *s = new Surface(filePath);
surfaces[path] = s;
Surface *s = Surface::loadImage(filePath);
if (s != NULL) {
surfaces[path] = s;
}
return s;
}
@@ -94,9 +96,10 @@ Surface *SurfaceCollection::addSkinRes(const string &path) {
string skinpath = getSkinFilePath(path);
if (skinpath.empty())
return NULL;
Surface *s = new Surface(skinpath);
if (s != NULL)
Surface *s = Surface::loadImage(skinpath);
if (s != NULL) {
surfaces[path] = s;
}
return s;
}