Skip to content

Commit

Permalink
Fix potential crash in benchmark mode with no console attached
Browse files Browse the repository at this point in the history
Fixes #1175
  • Loading branch information
SaschaWillems committed Jan 4, 2025
1 parent 0253944 commit 6f07d04
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions base/benchmark.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Benchmark class - Can be used for automated benchmarks
*
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
Expand Down Expand Up @@ -36,12 +36,15 @@ namespace vks
active = true;
this->deviceProps = deviceProps;
#if defined(_WIN32)
AttachConsole(ATTACH_PARENT_PROCESS);
freopen_s(&stream, "CONOUT$", "w+", stdout);
freopen_s(&stream, "CONOUT$", "w+", stderr);
bool consoleAttached = AttachConsole(ATTACH_PARENT_PROCESS);
if (!consoleAttached) {
consoleAttached = AttachConsole(GetCurrentProcessId());
}
if (consoleAttached) {
freopen_s(&stream, "CONOUT$", "w+", stdout);
freopen_s(&stream, "CONOUT$", "w+", stderr);
}
#endif
std::cout << std::fixed << std::setprecision(3);

// Warm up phase to get more stable frame rates
{
double tMeasured = 0.0;
Expand All @@ -64,7 +67,8 @@ namespace vks
frameCount++;
if (outputFrames != -1 && outputFrames == frameCount) break;
};
std::cout << "Benchmark finished" << "\n";
std::cout << std::fixed << std::setprecision(3);
std::cout << "Benchmark finished\n";
std::cout << "device : " << deviceProps.deviceName << " (driver version: " << deviceProps.driverVersion << ")" << "\n";
std::cout << "runtime: " << (runtime / 1000.0) << "\n";
std::cout << "frames : " << frameCount << "\n";
Expand Down

0 comments on commit 6f07d04

Please sign in to comment.