Skip to content

Commit

Permalink
RENDERER: Fix reading source in levelshot command
Browse files Browse the repository at this point in the history
Fix using offset for source returned by RB_ReadPixels(). In practice
this shouldn't be an issue because Hunk_AllocateTempMemory() should
already be aligned to sizeof(intptr_t).
  • Loading branch information
zturtleman committed May 24, 2024
1 parent d856a96 commit 6b1dd17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions code/renderergl1/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ sampled down from full screen distorted images
*/
static void R_LevelShot(screenshotType_e type, const char *ext) {
char fileName[MAX_OSPATH];
byte *source;
byte *source, *allsource;
byte *resample, *resamplestart;
size_t offset = 0, memcount;
int spadlen, rpadlen;
Expand Down Expand Up @@ -511,7 +511,8 @@ static void R_LevelShot(screenshotType_e type, const char *ext) {

Com_sprintf(fileName, sizeof(fileName), "levelshots/%s%s", tr.world->baseName, ext);

source = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen);
allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen);
source = allsource + offset;

linelen = width * 3;
padwidth = spadlen + linelen;
Expand Down Expand Up @@ -560,7 +561,7 @@ static void R_LevelShot(screenshotType_e type, const char *ext) {
RE_SavePNG(fileName, width, height, resample + offset, rpadlen);

ri.Hunk_FreeTempMemory(resample);
ri.Hunk_FreeTempMemory(source);
ri.Hunk_FreeTempMemory(allsource);

ri.Printf(PRINT_ALL, "Wrote %s\n", fileName);
}
Expand Down
7 changes: 4 additions & 3 deletions code/renderergl2/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ the menu system, sampled down from full screen distorted images
*/
static void R_LevelShot(screenshotType_e type, const char *ext) {
char fileName[MAX_OSPATH];
byte *source;
byte *source, *allsource;
byte *resample, *resamplestart;
size_t offset = 0, memcount;
int spadlen, rpadlen;
Expand Down Expand Up @@ -600,7 +600,8 @@ static void R_LevelShot(screenshotType_e type, const char *ext) {

Com_sprintf(fileName, sizeof(fileName), "levelshots/%s%s", tr.world->baseName, ext);

source = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen);
allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen);
source = allsource + offset;

linelen = width * 3;
padwidth = spadlen + linelen;
Expand Down Expand Up @@ -650,7 +651,7 @@ static void R_LevelShot(screenshotType_e type, const char *ext) {
RE_SavePNG(fileName, width, height, resample + offset, rpadlen);

ri.Hunk_FreeTempMemory(resample);
ri.Hunk_FreeTempMemory(source);
ri.Hunk_FreeTempMemory(allsource);

ri.Printf(PRINT_ALL, "Wrote %s\n", fileName);
}
Expand Down

0 comments on commit 6b1dd17

Please sign in to comment.