1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

Fix crash caused by thread clobbering

This commit is contained in:
Daniel Evans 2015-07-09 18:29:38 +01:00
parent 243bfb18a8
commit e2bd2b704e
4 changed files with 18 additions and 9 deletions

View File

@ -7,6 +7,7 @@
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <set>
#define SCM_NEGATE_CONDITIONAL_MASK 0x8000
@ -205,7 +206,7 @@ public:
void startThread(SCMThread::pc_t start, bool mission = false);
std::vector<SCMThread>& getThreads() { return _activeThreads; }
std::list<SCMThread>& getThreads() { return _activeThreads; }
SCMByte* getGlobals();
std::vector<SCMByte>& getGlobalData() { return globalData; }
@ -249,7 +250,7 @@ private:
GameState* state;
bool interupt;
std::vector<SCMThread> _activeThreads;
std::list<SCMThread> _activeThreads;
void executeThread(SCMThread& t, int msPassed);

View File

@ -240,12 +240,13 @@ SCMByte *ScriptMachine::getGlobals()
void ScriptMachine::execute(float dt)
{
int ms = dt * 1000.f;
for(size_t ti = 0; ti < _activeThreads.size(); ++ti) {
auto& thread = _activeThreads[ti];
for(auto t = _activeThreads.begin(); t != _activeThreads.end(); ++t )
{
auto& thread = *t;
executeThread( thread, ms );
if( thread.finished ) {
_activeThreads.erase( _activeThreads.begin() + ti );
t = _activeThreads.erase( t );
}
}
}

View File

@ -134,7 +134,14 @@ RWGame::RWGame(const std::string& gamepath, int argc, char* argv[])
auto loading = new LoadingState(this);
if( newgame )
{
loading->setNextState(new IngameState(this,true, "test"));
if( test )
{
loading->setNextState(new IngameState(this,true, "test"));
}
else
{
loading->setNextState(new IngameState(this,true));
}
}
else if( ! startSave.empty() )
{

View File

@ -313,12 +313,12 @@ std::string HttpServer::getState() const
ss << R"("status":"interrupted",)";
ss << R"("breakpoint": )" << breakpoint(lastBreakpoint) << ",";
ss << R"("threads": [)";
for(unsigned int i = 0; i < game->getScript()->getThreads().size(); ++i)
auto it = game->getScript()->getThreads().begin();
for(unsigned int i = 0; i < game->getScript()->getThreads().size(); ++i,++it)
{
if( i != 0 )
ss << ",";
SCMThread& th = game->getScript()->getThreads().at(i);
ss << thread(game->getScript(), th);
ss << thread(game->getScript(), *it);
}
ss << R"(])";
ss << "}";