Skip to content

Commit 01a9449

Browse files
committed
fix: crash caused by create_directory throwing
In some envirements POB may not have the permissions to create a new folder. This causes the current call to create_directory to throw an exception which is not handled causing a crash. This commit implements a check for error code of create_directory with an apropriate log message.
1 parent 50ea594 commit 01a9449

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

engine/render/r_main.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,16 +1887,21 @@ void r_renderer_c::DoScreenshot(image_c* i, const char* ext)
18871887
// curTimeSt.tm_mon+1, curTimeSt.tm_mday, curTimeSt.tm_year%100,
18881888
// curTimeSt.tm_hour, curTimeSt.tm_min, curTimeSt.tm_sec, ext);
18891889

1890+
18901891
// Make folder if it doesn't exist
1891-
std::filesystem::create_directory(CFG_DATAPATH "Screenshots");
1892-
1893-
// Save image
1892+
std::error_code ec;
1893+
std::filesystem::create_directory(CFG_DATAPATH "Screenshots", ec);
1894+
if (ec) {
1895+
sys->con->Print("Couldn't create screenshot folder!\n");
1896+
return;
1897+
}
1898+
18941899
if (i->Save(ssname.c_str())) {
18951900
sys->con->Print("Couldn't write screenshot!\n");
1901+
return;
18961902
}
1897-
else {
1898-
sys->con->Print(fmt::format("Wrote screenshot to {}\n", ssname).c_str());
1899-
}
1903+
1904+
sys->con->Print(fmt::format("Wrote screenshot to {}\n", ssname).c_str());
19001905
}
19011906

19021907
r_renderer_c::RenderTarget& r_renderer_c::GetDrawRenderTarget()

0 commit comments

Comments
 (0)