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