Add error handling to screenshot saving

This commit is contained in:
Joshua Ashton 2021-10-12 09:20:04 +01:00 committed by Simon Ser
parent 0aa6761157
commit c7a22d4777

View file

@ -1441,17 +1441,21 @@ paint_all(Display *dpy, MouseCursor *cursor)
imageData[y * pitch + x * comp + 3] = 255;
}
}
pCaptureTexture->nLockRefs--;
char pTimeBuffer[1024];
time_t currentTime = time(0);
struct tm *localTime = localtime( &currentTime );
strftime( pTimeBuffer, sizeof( pTimeBuffer ), "/tmp/gamescope_%Y-%m-%d_%H-%M-%S.png", localTime );
stbi_write_png(pTimeBuffer, currentOutputWidth, currentOutputHeight, 4, imageData.data(), pitch);
pCaptureTexture->nLockRefs--;
xwm_log.infof("Screenshot saved to %s", pTimeBuffer);
if ( stbi_write_png(pTimeBuffer, currentOutputWidth, currentOutputHeight, 4, imageData.data(), pitch) )
{
xwm_log.infof("Screenshot saved to %s", pTimeBuffer);
}
else
{
xwm_log.errorf( "Failed to save screenshot to %s", pTimeBuffer );
}
});
screenshotThread.detach();