Skip to content

Commit a552988

Browse files
committed
fix: fix windows compilation
1 parent 9321553 commit a552988

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

src/game/layout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#include "./layout.hpp"
33

4-
std::vector<ui::Layout> game::get_layouts_for(u32 players, const ui::Layout& layout) {
4+
std::vector<ui::Layout> game::get_layouts_for(std::size_t players, const ui::Layout& layout) {
55

66
std::vector<ui::Layout> layouts{};
77
layouts.reserve(players);

src/game/layout.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
#include "helper/windows.hpp"
88
#include "ui/layout.hpp"
9-
9+
#include <vector>
1010

1111
namespace game {
1212
OOPETRIS_GRAPHICS_EXPORTED [[nodiscard]] std::vector<ui::Layout>
13-
get_layouts_for(u32 players, const ui::Layout& layout);
13+
get_layouts_for(std::size_t players, const ui::Layout& layout);
1414

1515
}

src/graphics/video_renderer_windows.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <windows.h>
88

9+
#include <strstream>
910

1011
struct Decoder {
1112
HANDLE hProcess;
@@ -67,21 +68,39 @@ std::optional<std::string> VideoRendererBackend::setup(u32 fps, shapes::UPoint s
6768

6869
auto paramaters = VideoRendererBackend::get_encoding_paramaters(fps, size, m_destination_path);
6970

70-
std::stringstream args = "ffmpeg.exe";
71+
std::stringstream args{};
72+
args << "ffmpeg.exe";
73+
7174
for (const auto& parameter : paramaters) {
72-
args += " ";
73-
if (paramater.find(" ") != std::string::npos) {
74-
args += "\"";
75-
args += paramater;
76-
args += "\"";
75+
args << " ";
76+
if (parameter.find(" ") != std::string::npos) {
77+
args << "\"";
78+
args << parameter;
79+
args << "\"";
7780

7881
} else {
79-
args += paramater;
82+
args << parameter;
8083
}
8184
}
8285

86+
std::string result = args.str();
87+
auto str_size = result.size();
88+
89+
using UniqueCharArray = std::unique_ptr<char, std::function<void(const char* const)>>;
90+
91+
UniqueCharArray raw_args{ new char[str_size + 1], [](const char* const char_value) {
92+
if (char_value == nullptr) {
93+
return;
94+
}
95+
96+
delete[] char_value; // NOLINT(cppcoreguidelines-owning-memory)
97+
} };
98+
99+
std::memcpy(raw_args.get(), result.c_str(), str_size);
100+
raw_args.get()[str_size] = '\0';
101+
83102

84-
if (!CreateProcess(NULL, result.string().c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo)) {
103+
if (!CreateProcess(NULL, raw_args.get(), NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo)) {
85104
CloseHandle(pipe_write);
86105
CloseHandle(pipe_read);
87106

0 commit comments

Comments
 (0)