summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2015-12-21 01:05:55 -0800
committerTim Angus <tim@ngus.net>2016-04-07 11:46:04 +0100
commit5e21024a3ce91664273d61f26de679e6a5e9a213 (patch)
treef92805fe194180a496bbf21fc454d6991280905f
parent674b8eeefffd56bf2454c08a4ba21682788dc3af (diff)
Fix error handling in RE_SaveJPGToBuffer().
-rw-r--r--src/renderercommon/tr_image_jpg.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/renderercommon/tr_image_jpg.c b/src/renderercommon/tr_image_jpg.c
index 15c280d5..3e369c20 100644
--- a/src/renderercommon/tr_image_jpg.c
+++ b/src/renderercommon/tr_image_jpg.c
@@ -62,7 +62,7 @@ static void R_JPGErrorExit(j_common_ptr cinfo)
(*cinfo->err->format_message) (cinfo, buffer);
- ri.Printf(PRINT_ALL, "R_LoadJPG() error: %s", buffer);
+ ri.Printf(PRINT_ALL, "Error: %s", buffer);
/* Return control to the setjmp point */
longjmp(jerr->setjmp_buffer, 1);
@@ -143,7 +143,7 @@ void R_LoadJPG(const char *filename, unsigned char **pic, int *width, int *heigh
ri.FS_FreeFile(fbuffer.v);
/* Append the filename to the error for easier debugging */
- ri.Printf(PRINT_ALL, ", file %s\n", filename);
+ ri.Printf(PRINT_ALL, ", loading file %s\n", filename);
return;
}
@@ -389,17 +389,29 @@ size_t RE_SaveJPGToBuffer(byte *buffer, size_t bufSize, int quality,
int image_width, int image_height, byte *image_buffer, int padding)
{
struct jpeg_compress_struct cinfo;
- struct jpeg_error_mgr jerr;
+ q_jpeg_error_mgr_t jerr;
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
my_dest_ptr dest;
int row_stride; /* physical row width in image buffer */
size_t outcount;
/* Step 1: allocate and initialize JPEG compression object */
- cinfo.err = jpeg_std_error(&jerr);
+ cinfo.err = jpeg_std_error(&jerr.pub);
cinfo.err->error_exit = R_JPGErrorExit;
cinfo.err->output_message = R_JPGOutputMessage;
+ /* Establish the setjmp return context for R_JPGErrorExit to use. */
+ if (setjmp(jerr.setjmp_buffer))
+ {
+ /* If we get here, the JPEG code has signaled an error.
+ * We need to clean up the JPEG object and return.
+ */
+ jpeg_destroy_compress(&cinfo);
+
+ ri.Printf(PRINT_ALL, "\n");
+ return 0;
+ }
+
/* Now we can initialize the JPEG compression object. */
jpeg_create_compress(&cinfo);