Skip to content

Commit 4f67f5f

Browse files
committed
REVIEWED: TakeScreenshot(), potential issues
1 parent 0873af4 commit 4f67f5f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/rcore.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,8 @@ void UnloadRandomSequence(int *sequence)
17661766
#endif
17671767
}
17681768

1769-
// Takes a screenshot of current screen (saved a .png)
1769+
// Takes a screenshot of current screen
1770+
// NOTE: Provided fileName should not contain paths, saving to working directory
17701771
void TakeScreenshot(const char *fileName)
17711772
{
17721773
#if defined(SUPPORT_MODULE_RTEXTURES)
@@ -1778,12 +1779,13 @@ void TakeScreenshot(const char *fileName)
17781779
Image image = { imgData, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y), 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
17791780

17801781
char path[512] = { 0 };
1781-
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, fileName));
1782-
1782+
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, GetFileName(fileName)));
1783+
17831784
ExportImage(image, path); // WARNING: Module required: rtextures
17841785
RL_FREE(imgData);
17851786

1786-
TRACELOG(LOG_INFO, "SYSTEM: [%s] Screenshot taken successfully", path);
1787+
if (FileExists(path)) TRACELOG(LOG_INFO, "SYSTEM: [%s] Screenshot taken successfully", path);
1788+
else TRACELOG(LOG_WARNING, "SYSTEM: [%s] Screenshot could not be saved", path);
17871789
#else
17881790
TRACELOG(LOG_WARNING,"IMAGE: ExportImage() requires module: rtextures");
17891791
#endif
@@ -1836,10 +1838,10 @@ bool IsFileExtension(const char *fileName, const char *ext)
18361838
{
18371839
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_TEXT_MANIPULATION)
18381840
int extCount = 0;
1839-
const char **checkExts = TextSplit(ext, ';', &extCount); // WARNING: Module required: rtext
1841+
const char **checkExts = TextSplit(ext, ';', &extCount); // WARNING: Module required: rtext
18401842

18411843
char fileExtLower[MAX_FILE_EXTENSION_SIZE + 1] = { 0 };
1842-
strncpy(fileExtLower, TextToLower(fileExt), MAX_FILE_EXTENSION_SIZE); // WARNING: Module required: rtext
1844+
strncpy(fileExtLower, TextToLower(fileExt), MAX_FILE_EXTENSION_SIZE); // WARNING: Module required: rtext
18431845

18441846
for (int i = 0; i < extCount; i++)
18451847
{

0 commit comments

Comments
 (0)