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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user