Skip to content

Commit

Permalink
Hotfix for #355 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mwydmuch committed Nov 15, 2018
1 parent 32d86d5 commit a1a1128
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 44 deletions.
83 changes: 46 additions & 37 deletions src/lib/ViZDoomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "ViZDoomPathHelpers.h"
#include "ViZDoomUtilities.h"
#include "ViZDoomVersion.h"
#include "boost/process.hpp"

#include <boost/algorithm/string.hpp>
#include <boost/chrono.hpp>
Expand All @@ -37,8 +36,6 @@ namespace vizdoom {
namespace bal = boost::algorithm;
namespace bc = boost::chrono;
namespace bfs = boost::filesystem;
namespace bpr = boost::process;
namespace bpri = boost::process::initializers;


/* Public methods */
Expand Down Expand Up @@ -198,54 +195,63 @@ namespace vizdoom {
}

void DoomController::close() {
try{
if (this->doomRunning) {
this->doomRunning = false;
this->doomWorking = false;

this->MQDoom->send(MSG_CODE_CLOSE);

#ifdef OS_LINUX
if(0 == kill(this->doomProcessPid, 0)){
bpr::child doomProcess(this->doomProcessPid);
bpr::terminate(doomProcess);
}
#endif
}

if (this->doomRunning) {

this->doomRunning = false;
this->doomWorking = false;

this->MQDoom->send(MSG_CODE_CLOSE);
}

if (this->signalThread && this->signalThread->joinable()) {
this->ioService->stop();
if (this->signalThread && this->signalThread->joinable()) {
this->ioService->stop();

this->signalThread->interrupt();
this->signalThread->join();
delete this->signalThread;
this->signalThread = nullptr;
this->signalThread->interrupt();
this->signalThread->join();
delete this->signalThread;
this->signalThread = nullptr;

delete this->ioService;
this->ioService = nullptr;
}
delete this->ioService;
this->ioService = nullptr;
}

if (this->doomThread && this->doomThread->joinable()) {
this->doomThread->interrupt();
this->doomThread->join();
delete this->doomThread;
this->doomThread = nullptr;
}
if (this->doomThread && this->doomThread->joinable()) {
this->doomThread->interrupt();
this->doomThread->join();
delete this->doomThread;
this->doomThread = nullptr;
}

if (this->SM) {
delete this->SM;
this->SM = nullptr;
}
if (this->SM) {
delete this->SM;
this->SM = nullptr;
}

if (this->MQDoom) {
delete this->MQDoom;
this->MQDoom = nullptr;
}
if (this->MQController) {
delete this->MQController;
this->MQController = nullptr;
if (this->MQDoom) {
delete this->MQDoom;
this->MQDoom = nullptr;
}
if (this->MQController) {
delete this->MQController;
this->MQController = nullptr;
}
}
catch (...) { throw; }

this->gameState = nullptr;
this->input = nullptr;
this->screenBuffer = nullptr;
this->depthBuffer = nullptr;
this->labelsBuffer = nullptr;
this->automapBuffer = nullptr;

}

void DoomController::restart() {
Expand Down Expand Up @@ -1338,6 +1344,9 @@ namespace vizdoom {
void DoomController::launchDoom() {
try {
bpr::child doomProcess = bpr::execute(bpri::set_args(this->doomArgs), bpri::inherit_env());
#ifdef OS_LINUX
this->doomProcessPid = doomProcess.pid;
#endif
bpr::wait_for_exit(doomProcess);
}
catch (...) {
Expand Down
10 changes: 9 additions & 1 deletion src/lib/ViZDoomController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ViZDoomTypes.h"
#include "ViZDoomMessageQueue.h"
#include "ViZDoomSharedMemory.h"
#include "boost/process.hpp"

#include <boost/asio.hpp>
#include <boost/random.hpp>
Expand All @@ -40,6 +41,9 @@ namespace vizdoom {
namespace bip = boost::interprocess;
namespace br = boost::random;
namespace bs = boost::system;
namespace bpr = boost::process;
namespace bpri = boost::process::initializers;


#define INSTANCE_ID_LENGTH 10

Expand Down Expand Up @@ -70,6 +74,8 @@ namespace vizdoom {
/* OSes */
#ifdef __linux__
#define OS_LINUX
#include <sys/types.h>
#include <signal.h>
#elif _WIN32
#define OS_WIN
#elif __APPLE__
Expand Down Expand Up @@ -292,8 +298,10 @@ namespace vizdoom {
void intSignal(int sigNumber);

b::thread *doomThread;
//bpr::child doomProcess;

#ifdef OS_LINUX
pid_t doomProcessPid;
#endif

/* Message queues */
/*------------------------------------------------------------------------------------------------------------*/
Expand Down
9 changes: 6 additions & 3 deletions src/lib/ViZDoomGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ namespace vizdoom {

void DoomGame::close() {
if (this->isRunning()) {
this->doomController->close();
try {
this->doomController->close();
}
catch (...) { throw; }

this->lastAction.clear();
this->nextAction.clear();

Expand Down Expand Up @@ -162,10 +166,9 @@ namespace vizdoom {
if (this->doomController->isTicPossible()) {
try {
this->doomController->tics(tics, updateState);
if (updateState) this->updateState();
}
catch (...) { throw; }

if (updateState) this->updateState();
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/vizdoom/src/posix/sdl/crashcatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ static void crash_catcher(int signum, siginfo_t *siginfo, void *context)
crash_info.has_siginfo = !!siginfo;
if(siginfo)
crash_info.siginfo = *siginfo;
if(cc_user_info)
cc_user_info(crash_info.buf, crash_info.buf+sizeof(crash_info.buf));

//VIZDOOM_CODE
// if(cc_user_info)
// cc_user_info(crash_info.buf, crash_info.buf+sizeof(crash_info.buf));

/* Fork off to start a crash handler */
switch((dbg_pid=fork()))
switch((dbg_pid=fork()))
{
/* Error */
case -1:
Expand Down

0 comments on commit a1a1128

Please sign in to comment.