Fix potential crash in benchmark mode with no console attached
Fixes #1175
This commit is contained in:
parent
025394453d
commit
6f07d042b6
1 changed files with 11 additions and 7 deletions
|
|
@ -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)
|
||||
*/
|
||||
|
|
@ -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;
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue