Skip to content

Commit

Permalink
Fix GRPC Server Compile Game Crashes (#1902)
Browse files Browse the repository at this point in the history
* Change emake plugin proto compile method to take a const reference and copy the game into project rather than transfer ownership which caused double delete.
* Use reference capture in proto compile RPC method instead of value capture and copying/casting.
* Update GRPC server to use standard filesystem rather than the Boost one.
  • Loading branch information
RobertBColton authored Mar 8, 2020
1 parent d5fc829 commit 6198eb1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CommandLine/emake/EnigmaPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ int EnigmaPlugin::BuildGame(deprecated::JavaStruct::EnigmaStruct* data,
return plugin_CompileEGM(data, fpath, mode);
}

int EnigmaPlugin::BuildGame(buffers::Game* data, GameMode mode, const char* fpath)
int EnigmaPlugin::BuildGame(const buffers::Game& data, GameMode mode, const char* fpath)
{
buffers::Project proj;
proj.set_allocated_game(data);
proj.mutable_game()->CopyFrom(data);
return plugin_CompileProto(&proj, fpath, mode);
}

Expand Down
2 changes: 1 addition & 1 deletion CommandLine/emake/EnigmaPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EnigmaPlugin
void HandleGameLaunch();
void LogMakeToConsole();
int BuildGame(deprecated::JavaStruct::EnigmaStruct* data, GameMode mode, const char* fpath);
int BuildGame(buffers::Game* data, GameMode mode, const char* fpath);
int BuildGame(const buffers::Game& data, GameMode mode, const char* fpath);
const char* NextResource();
const char* FirstResource();
bool ResourceIsFunction();
Expand Down
6 changes: 3 additions & 3 deletions CommandLine/emake/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int main(int argc, char* argv[])
} else if (ext == "gm81" || ext == "gmk" || ext == "gm6" || ext == "gmd") {
buffers::Project* project;
if (!(project = gmk::LoadGMK(input_file))) return 1;
return plugin.BuildGame(project->mutable_game(), mode, output_file.c_str());
return plugin.BuildGame(project->game(), mode, output_file.c_str());
} else if (ext == "gmx") {
fs::path p = input_file;
if (fs::is_directory(p)) {
Expand All @@ -149,11 +149,11 @@ int main(int argc, char* argv[])

buffers::Project* project;
if (!(project = gmx::LoadGMX(input_file))) return 1;
return plugin.BuildGame(project->mutable_game(), mode, output_file.c_str());
return plugin.BuildGame(project->game(), mode, output_file.c_str());
} else if (ext == "yyp") {
buffers::Project* project;
if (!(project = yyp::LoadYYP(input_file))) return 1;
return plugin.BuildGame(project->mutable_game(), mode, output_file.c_str());
return plugin.BuildGame(project->game(), mode, output_file.c_str());
#endif
} else {
if (ext == "egm") {
Expand Down
12 changes: 6 additions & 6 deletions CommandLine/emake/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>

#include <boost/filesystem.hpp>

#include <filesystem>
#include <memory>
#include <future>

namespace fs = std::filesystem;

using namespace grpc;
using namespace buffers;

Expand All @@ -27,9 +28,8 @@ class CompilerServiceImpl final : public Compiler::Service {

Status CompileBuffer(ServerContext* /*context*/, const CompileRequest* request, ServerWriter<CompileReply>* writer) override {
// use lambda capture to contain compile logic
auto fnc = [=] {
const CompileRequest req = *request;
plugin.BuildGame(const_cast<buffers::Game*>(&req.game()), emode_run, req.name().c_str());
auto fnc = [&] {
plugin.BuildGame(request->game(), emode_run, request->name().c_str());
};
// asynchronously launch the compile request
std::future<void> future = std::async(fnc);
Expand Down Expand Up @@ -116,7 +116,7 @@ class CompilerServiceImpl final : public Compiler::Service {
id = about.get("id"); // allow alias
if (id.empty()) {
// compilers use filename minus ext as id
boost::filesystem::path ey(subsystem);
fs::path ey(subsystem);
id = ey.stem().string();
}

Expand Down

0 comments on commit 6198eb1

Please sign in to comment.