Skip to content

Commit b3f78e5

Browse files
committed
Fix Windows vizdoom_lib process launch
1 parent 7485086 commit b3f78e5

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

envpool/workspace0.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,13 @@ perl -Iperllib -I. macros/macros.pl version.mac 'macros/*.mac' 'output/*.mac'
406406
maybe(
407407
http_archive,
408408
name = "vizdoom_lib",
409+
patch_args = [
410+
"-p0",
411+
"-l",
412+
],
413+
patches = [
414+
"//third_party/vizdoom_lib:windows_create_process.patch",
415+
],
409416
sha256 = "76ddf186d7f093ef85cbcb0e7e387757d60e45190eb5da6d075aab31ffc316ed",
410417
strip_prefix = "ViZDoom-1.3.0/",
411418
urls = [
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--- src/lib/ViZDoomController.h
2+
+++ src/lib/ViZDoomController.h
3+
@@ -29,0 +30,2 @@
4+
+#else
5+
+ #include "boost/process.hpp"
6+
@@ -35 +36,0 @@
7+
-#include "boost/process.hpp"
8+
@@ -52,0 +54 @@
9+
+#ifndef _WIN32
10+
@@ -54,0 +57 @@
11+
+#endif
12+
--- src/lib/ViZDoomController.cpp
13+
+++ src/lib/ViZDoomController.cpp
14+
@@ -33,0 +34 @@
15+
+#include <stdexcept>
16+
@@ -36,0 +38,28 @@
17+
+
18+
+#ifdef OS_WIN
19+
+ namespace {
20+
+ std::string quoteCommandArg(const std::string &arg) {
21+
+ if (arg.empty()) return "\"\"";
22+
+ if (arg.find_first_of(" \t\"") == std::string::npos) return arg;
23+
+
24+
+ std::string quoted = "\"";
25+
+ size_t backslashes = 0;
26+
+ for (char ch : arg) {
27+
+ if (ch == '\\') {
28+
+ ++backslashes;
29+
+ } else if (ch == '"') {
30+
+ quoted.append(backslashes * 2 + 1, '\\');
31+
+ quoted.push_back('"');
32+
+ backslashes = 0;
33+
+ } else {
34+
+ quoted.append(backslashes, '\\');
35+
+ backslashes = 0;
36+
+ quoted.push_back(ch);
37+
+ }
38+
+ }
39+
+ quoted.append(backslashes * 2, '\\');
40+
+ quoted.push_back('"');
41+
+ return quoted;
42+
+ }
43+
+ }
44+
+#endif
45+
@@ -1473,0 +1503,18 @@
46+
+#ifdef OS_WIN
47+
+ std::string commandLine;
48+
+ for (size_t i = 0; i < this->doomArgs.size(); ++i) {
49+
+ if (i != 0) commandLine += " ";
50+
+ commandLine += quoteCommandArg(this->doomArgs[i]);
51+
+ }
52+
+
53+
+ STARTUPINFOA startupInfo = { sizeof(startupInfo) };
54+
+ PROCESS_INFORMATION processInfo = {};
55+
+ std::vector<char> commandLineBuffer(commandLine.begin(), commandLine.end());
56+
+ commandLineBuffer.push_back('\0');
57+
+
58+
+ if (!CreateProcessA(NULL, commandLineBuffer.data(), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo))
59+
+ throw std::runtime_error("Failed to launch ViZDoom process.");
60+
+ WaitForSingleObject(processInfo.hProcess, INFINITE);
61+
+ CloseHandle(processInfo.hThread);
62+
+ CloseHandle(processInfo.hProcess);
63+
+#else
64+
@@ -1478,0 +1526 @@
65+
+#endif

0 commit comments

Comments
 (0)