Fix a memleak pointed by @Zeno- in MeshUpdateQueue
[oweals/minetest.git] / src / porting.cpp
index 4786a2a390967183752eb8374475889a5a8f9a4a..10b6fc94059c675af85165b669e65518bd606611 100644 (file)
@@ -408,7 +408,7 @@ bool setSystemPaths()
 #endif
 
        for (std::list<std::string>::const_iterator
-                       i = trylist.begin(); i != trylist.end(); i++) {
+                       i = trylist.begin(); i != trylist.end(); ++i) {
                const std::string &trypath = *i;
                if (!fs::PathExists(trypath) ||
                        !fs::PathExists(trypath + DIR_DELIM + "builtin")) {
@@ -929,4 +929,31 @@ bool secure_rand_fill_buf(void *buf, size_t len)
 
 #endif
 
+void attachOrCreateConsole(void)
+{
+#ifdef _WIN32
+       static bool consoleAllocated = false;
+       const bool redirected = (_fileno(stdout) == -2 || _fileno(stdout) == -1); // If output is redirected to e.g a file
+       if (!consoleAllocated && redirected && (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())) {
+               freopen("CONOUT$", "w", stdout);
+               freopen("CONOUT$", "w", stderr);
+               consoleAllocated = true;
+       }
+#endif
+}
+
+// Load performance counter frequency only once at startup
+#ifdef _WIN32
+
+inline double get_perf_freq()
+{
+       LARGE_INTEGER freq;
+       QueryPerformanceFrequency(&freq);
+       return freq.QuadPart;
+}
+
+double perf_freq = get_perf_freq();
+
+#endif
+
 } //namespace porting