Skip to content

Commit

Permalink
Merge pull request #64 from Paliak/exception-check-create_directory
Browse files Browse the repository at this point in the history
Add basic error checking to create_directory in `r_renderer_c::DoScreenshot` to prevent crash
  • Loading branch information
Wires77 authored Jan 19, 2025
2 parents 44f2951 + 01a9449 commit bf09102
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions engine/render/r_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1940,16 +1940,21 @@ void r_renderer_c::DoScreenshot(image_c* i, int type, const char* ext)
// curTimeSt.tm_mon+1, curTimeSt.tm_mday, curTimeSt.tm_year%100,
// curTimeSt.tm_hour, curTimeSt.tm_min, curTimeSt.tm_sec, ext);


// Make folder if it doesn't exist
std::filesystem::create_directory(CFG_DATAPATH "Screenshots");

// Save image
std::error_code ec;
std::filesystem::create_directory(CFG_DATAPATH "Screenshots", ec);
if (ec) {
sys->con->Print("Couldn't create screenshot folder!\n");
return;
}

if (i->Save(ssname.c_str())) {
sys->con->Print("Couldn't write screenshot!\n");
return;
}
else {
sys->con->Print(fmt::format("Wrote screenshot to {}\n", ssname).c_str());
}

sys->con->Print(fmt::format("Wrote screenshot to {}\n", ssname).c_str());
}

r_renderer_c::RenderTarget& r_renderer_c::GetDrawRenderTarget()
Expand Down

0 comments on commit bf09102

Please sign in to comment.