1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-11 17:04:15 +01:00

WPrefs: fix segfault when image not found

Previously, when an image could not be loaded by WPrefs when rendering textures
for the Appearances panel, a segfault would occur.  This could happen, e.g., if
a user moved or deleted an image file without editing their ~/GNUstep/Defaults/
WindowMaker file.

This patch first checks if a texture contains an image, and if it does, it
checks to see if that image can be loaded.  If it can't, a solid black texture
is loaded instead.

The patch also has the added benefit of combining some of the code used for
rendering both pixmap and textured gradient textures.
This commit is contained in:
Doug Torrance
2014-05-15 22:12:57 -05:00
committed by Carlos R. Mafra
parent 3b71662011
commit 96c9ec185a

View File

@@ -491,6 +491,7 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int
{
char *type;
RImage *image = NULL;
RImage *timage = NULL;
Pixmap pixmap;
RContext *rc = WMScreenRContext(scr);
char *str;
@@ -498,6 +499,23 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int
type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
if (strcasecmp(&type[1], "pixmap") == 0 ||
(strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T')) {
char *path;
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
path = wfindfileinarray(GetObjectForKey("PixmapPath"), str);
if (path) {
timage = RLoadImage(rc, path, 0);
if (!timage) {
wwarning("could not load file '%s': %s", path ? path : str, RMessageForError(RErrorCode));
texture = WMCreatePropListFromDescription("(solid, black)");
type = "solid";
}
wfree(path);
}
}
if (strcasecmp(type, "solid") == 0) {
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
@@ -552,8 +570,7 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int
int style;
RColor rcolor2;
int i;
RImage *grad, *timage = NULL;
char *path;
RImage *grad = NULL;
switch (toupper(type[1])) {
case 'V':
@@ -573,24 +590,16 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int
str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
str2rcolor(rc, str, &rcolor2);
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
if ((path = wfindfileinarray(GetObjectForKey("PixmapPath"), str)) != NULL)
timage = RLoadImage(rc, path, 0);
image = RMakeTiledImage(timage, width, height);
RReleaseImage(timage);
if (!path || !timage) {
wwarning("could not load file '%s': %s", path, RMessageForError(RErrorCode));
} else {
grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
image = RMakeTiledImage(timage, width, height);
RReleaseImage(timage);
RCombineImagesWithOpaqueness(image, grad, i);
RReleaseImage(grad);
i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
RCombineImagesWithOpaqueness(image, grad, i);
RReleaseImage(grad);
}
} else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
int style;
RColor **colors;
@@ -628,42 +637,29 @@ static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int
wfree(colors);
}
} else if (strcasecmp(&type[1], "pixmap") == 0) {
RImage *timage = NULL;
char *path;
RColor color;
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
if ((path = wfindfileinarray(GetObjectForKey("PixmapPath"), str)) != NULL)
timage = RLoadImage(rc, path, 0);
if (!path || !timage) {
wwarning("could not load file '%s': %s", path ? path : str, RMessageForError(RErrorCode));
} else {
str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
str2rcolor(rc, str, &color);
switch (toupper(type[0])) {
case 'T':
image = RMakeTiledImage(timage, width, height);
RReleaseImage(timage);
timage = image;
break;
case 'C':
image = RMakeCenteredImage(timage, width, height, &color);
RReleaseImage(timage);
timage = image;
break;
case 'S':
case 'M':
image = RScaleImage(timage, width, height);
RReleaseImage(timage);
timage = image;
break;
}
str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
str2rcolor(rc, str, &color);
switch (toupper(type[0])) {
case 'T':
image = RMakeTiledImage(timage, width, height);
RReleaseImage(timage);
timage = image;
break;
case 'C':
image = RMakeCenteredImage(timage, width, height, &color);
RReleaseImage(timage);
timage = image;
break;
case 'S':
case 'M':
image = RScaleImage(timage, width, height);
RReleaseImage(timage);
timage = image;
break;
}
wfree(path);
}
if (!image)