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.
---
WPrefs.app/Appearance.c | 91 +++++++++++++++++++++++--------------------------
1 file changed, 43 insertions(+), 48 deletions(-)
diff --git a/WPrefs.app/Appearance.c b/WPrefs.app/Appearance.c
index 12ee13c..861b1ab 100644
--- a/WPrefs.app/Appearance.c
+++ b/WPrefs.app/Appearance.c
@@ -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,22 @@ 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));
+ 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));
+ texture = WMCreatePropListFromDescription("(solid,
black)");
+ type = "solid";
+ }
+ wfree(path);
+ }
+
if (strcasecmp(type, "solid") == 0) {
str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
@@ -552,8 +569,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 +589,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 +636,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)
--
1.9.1
--
To unsubscribe, send mail to [email protected].