From 1dc482677d22fbc03928f6fd73f7fd700ae0f77c Mon Sep 17 00:00:00 2001 From: sezero Date: Mon, 28 Apr 2014 08:12:42 +0000 Subject: [PATCH] fix screenshots when width isn't a multiple of 4. explained by Sander van Dijk. also check that malloc() didn't fail. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@909 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/gl_screen.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Quake/gl_screen.c b/Quake/gl_screen.c index ea66f964..ce887032 100644 --- a/Quake/gl_screen.c +++ b/Quake/gl_screen.c @@ -118,6 +118,7 @@ float scr_disabled_time; int scr_tileclear_updates = 0; //johnfitz +static GLint gl_pack_alignment = 4; void SCR_ScreenShot_f (void); /* @@ -425,6 +426,7 @@ void SCR_Init (void) SCR_LoadPics (); //johnfitz + glGetIntegerv (GL_PACK_ALIGNMENT, &gl_pack_alignment); scr_initialized = true; } @@ -778,11 +780,17 @@ void SCR_ScreenShot_f (void) { Con_Printf ("SCR_ScreenShot_f: Couldn't find an unused filename\n"); return; - } + } //get data - buffer = (byte *) malloc(glwidth*glheight*3); + if (!(buffer = (byte *) malloc(glwidth*glheight*3))) + { + Con_Printf ("SCR_ScreenShot_f: Couldn't allocate memory\n"); + return; + } + glPixelStorei (GL_PACK_ALIGNMENT, 1);/* for widths that aren't a multiple of 4 */ glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer); + glPixelStorei (GL_PACK_ALIGNMENT, gl_pack_alignment); // now write the file if (Image_WriteTGA (tganame, buffer, glwidth, glheight, 24, false))