mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 22:44:59 +01:00
fix: the simulator opens more than 512 files at once, and a shader it can't open says why
With "physicslog yes" every driver keeps its .dat open, and a large scenery (Tomaszewo: some 500 vehicles, cars of the roads included) took all 512 streams the MSVC runtime gives: the next fopen failed and the simulator stopped at "cannot read shader: shaders/map.vert" on opening the map. The limit is raised to 8192 at the start (the soft limit of open files up to the hard one on Linux), and a shader file that doesn't open is told as such, with the system's reason, rather than as one that can't be read.
This commit is contained in:
24
EU07.cpp
24
EU07.cpp
@@ -27,6 +27,11 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <cstdio>
|
||||||
|
#else
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
#ifdef WITHDUMPGEN
|
#ifdef WITHDUMPGEN
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
@@ -136,10 +141,29 @@ void finish_log()
|
|||||||
end_test_run("the simulator stopped before the test ended");
|
end_test_run("the simulator stopped before the test ended");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// every vehicle with a driver keeps its physics log open for the whole run, and on a scenery with some five hundred
|
||||||
|
// of them the logs took all the files the C library of Windows lets a process have open by default (512): the
|
||||||
|
// files opened after them, the shaders of the map among them, couldn't be read. so the limit is raised to the most
|
||||||
|
// either system allows
|
||||||
|
void raise_open_files_limit()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
_setmaxstdio(8192);
|
||||||
|
#else
|
||||||
|
rlimit limit{};
|
||||||
|
if (getrlimit(RLIMIT_NOFILE, &limit) == 0 && limit.rlim_cur < limit.rlim_max)
|
||||||
|
{
|
||||||
|
limit.rlim_cur = limit.rlim_max;
|
||||||
|
setrlimit(RLIMIT_NOFILE, &limit);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
raise_open_files_limit();
|
||||||
#ifdef WITHDUMPGEN
|
#ifdef WITHDUMPGEN
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
SetUnhandledExceptionFilter(CrashHandler);
|
SetUnhandledExceptionFilter(CrashHandler);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include <cerrno>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <system_error>
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "glsl_common.h"
|
#include "glsl_common.h"
|
||||||
#include "utilities/Logs.h"
|
#include "utilities/Logs.h"
|
||||||
@@ -58,6 +60,12 @@ std::string gl::shader::read_file(const std::string &filename) const
|
|||||||
std::ifstream f;
|
std::ifstream f;
|
||||||
|
|
||||||
f.open(filename);
|
f.open(filename);
|
||||||
|
if (false == f.is_open())
|
||||||
|
{
|
||||||
|
// with the reason the system gives: a file which is there but can't be opened (too many files open) looks
|
||||||
|
// the same as a missing one otherwise
|
||||||
|
throw shader_exception("cannot open shader: " + filename + " (" + std::generic_category().message(errno) + ")");
|
||||||
|
}
|
||||||
stream << f.rdbuf();
|
stream << f.rdbuf();
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user