diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 9fe974d86..f609b80b7 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -72,8 +72,10 @@ CS::Editor::Editor (OgreInit::OgreInit& ogreInit) CS::Editor::~Editor () { + mPidFile.close(); + if(mServer && boost::filesystem::exists(mPid)) - remove(mPid.string().c_str()); // ignore error + remove(mPid.string().c_str()); // ignore any error // cleanup global resources used by OEngine delete OEngine::Physic::BulletShapeManager::getSingletonPtr(); @@ -246,7 +248,7 @@ bool CS::Editor::makeIPCServer() mPid /= "opencs.pid"; bool pidExists = boost::filesystem::exists(mPid); - boost::filesystem::ofstream tempFile(mPid); + mPidFile.open(mPid); mLock = boost::interprocess::file_lock(mPid.string().c_str()); if(!mLock.try_lock()) @@ -256,11 +258,10 @@ bool CS::Editor::makeIPCServer() } #ifdef _WIN32 - tempFile << GetCurrentProcessId() << std::endl; + mPidFile << GetCurrentProcessId() << std::endl; #else - tempFile << getpid() << std::endl; + mPidFile << getpid() << std::endl; #endif - tempFile.close(); mServer = new QLocalServer(this); diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index 30a031309..273f0825b 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -56,6 +57,7 @@ namespace CS boost::filesystem::path mResources; boost::filesystem::path mPid; boost::interprocess::file_lock mLock; + boost::filesystem::ofstream mPidFile; bool mFsStrict; void setupDataFiles (const Files::PathContainer& dataDirs);