- trying to trace nig's crash (more debug info and safer code)

This commit is contained in:
Mark Vejvoda 2013-01-23 14:51:28 +00:00
parent 141f7eaa48
commit 7ecc7325ac
15 changed files with 109 additions and 54 deletions

View File

@ -234,8 +234,9 @@ AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex,
}
workerThread = NULL;
}
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
this->workerThread = new AiInterfaceThread(this);
this->workerThread->setUniqueID(__FILE__);
this->workerThread->setUniqueID(mutexOwnerId);
this->workerThread->start();
}

View File

@ -257,8 +257,9 @@ Renderer::Renderer() : BaseRenderer() {
}
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
saveScreenShotThread = new SimpleTaskThread(this,0,25);
saveScreenShotThread->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str());
saveScreenShotThread->setUniqueID(mutexOwnerId);
saveScreenShotThread->start();
}
}
@ -266,20 +267,27 @@ Renderer::Renderer() : BaseRenderer() {
void Renderer::cleanupScreenshotThread() {
if(saveScreenShotThread) {
saveScreenShotThread->signalQuit();
for(time_t elapsed = time(NULL);
getSaveScreenQueueSize() > 0 && difftime((long int)time(NULL),elapsed) <= 7;) {
sleep(0);
}
if(saveScreenShotThread->canShutdown(true) == true &&
saveScreenShotThread->shutdownAndWait() == true) {
//printf("IN MenuStateCustomGame cleanup - C\n");
// for(time_t elapsed = time(NULL);
// getSaveScreenQueueSize() > 0 && difftime((long int)time(NULL),elapsed) <= 7;) {
// sleep(0);
// }
// if(saveScreenShotThread->canShutdown(true) == true &&
// saveScreenShotThread->shutdownAndWait() == true) {
// //printf("IN MenuStateCustomGame cleanup - C\n");
// delete saveScreenShotThread;
// }
// saveScreenShotThread = NULL;
if(saveScreenShotThread->shutdownAndWait() == true) {
delete saveScreenShotThread;
}
saveScreenShotThread = NULL;
if(getSaveScreenQueueSize() > 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] FORCING MEMORY CLEANUP and NOT SAVING screenshots, saveScreenQueue.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,saveScreenQueue.size());
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&saveScreenShotThreadAccessor,mutexOwnerId);
for(std::list<std::pair<string,Pixmap2D *> >::iterator iter = saveScreenQueue.begin();
iter != saveScreenQueue.end(); ++iter) {
delete iter->second;
@ -290,37 +298,57 @@ void Renderer::cleanupScreenshotThread() {
}
Renderer::~Renderer() {
delete modelRenderer;
modelRenderer = NULL;
delete textRenderer;
textRenderer = NULL;
delete textRenderer3D;
textRenderer3D = NULL;
delete particleRenderer;
particleRenderer = NULL;
try{
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//resources
for(int i=0; i<rsCount; ++i){
delete modelManager[i];
modelManager[i] = NULL;
delete textureManager[i];
textureManager[i] = NULL;
delete particleManager[i];
particleManager[i] = NULL;
delete fontManager[i];
fontManager[i] = NULL;
delete modelRenderer;
modelRenderer = NULL;
delete textRenderer;
textRenderer = NULL;
delete textRenderer3D;
textRenderer3D = NULL;
delete particleRenderer;
particleRenderer = NULL;
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//resources
for(int i=0; i<rsCount; ++i){
delete modelManager[i];
modelManager[i] = NULL;
delete textureManager[i];
textureManager[i] = NULL;
delete particleManager[i];
particleManager[i] = NULL;
delete fontManager[i];
fontManager[i] = NULL;
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// Wait for the queue to become empty or timeout the thread at 7 seconds
cleanupScreenshotThread();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
mapSurfaceData.clear();
quadCache = VisibleQuadContainerCache();
quadCache.clearFrustrumData();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
this->menu = NULL;
this->game = NULL;
this->gameCamera = NULL;
}
catch(const exception &e) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d]\nError [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,szBuf);
// Wait for the queue to become empty or timeout the thread at 7 seconds
cleanupScreenshotThread();
mapSurfaceData.clear();
quadCache = VisibleQuadContainerCache();
quadCache.clearFrustrumData();
this->menu = NULL;
this->game = NULL;
this->gameCamera = NULL;
throw megaglest_runtime_error(szBuf);
}
}
void Renderer::simpleTask(BaseThread *callingThread) {

View File

@ -4842,8 +4842,9 @@ int glestMain(int argc, char** argv) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] precache thread enabled = %d\n",__FILE__,__FUNCTION__,__LINE__,startCRCPrecacheThread);
if(startCRCPrecacheThread == true) {
vector<string> techDataPaths = config.getPathListForType(ptTechs);
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
preCacheThread = new FileCRCPreCacheThread();
preCacheThread->setUniqueID(__FILE__);
preCacheThread->setUniqueID(mutexOwnerId);
preCacheThread->setTechDataPaths(techDataPaths);
//preCacheThread->setFileCRCPreCacheThreadCallbackInterface(&preCacheThreadGame);
preCacheThread->start();

View File

@ -807,8 +807,9 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
if(BaseThread::shutdownAndWait(soundThreadManager) == true) {
delete soundThreadManager;
}
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,SOUND_THREAD_UPDATE_MILLISECONDS);
soundThreadManager->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str());
soundThreadManager->setUniqueID(mutexOwnerId);
soundThreadManager->start();
}
}
@ -886,8 +887,9 @@ void Program::stopSoundSystem() {
void Program::startSoundSystem() {
stopSoundSystem();
if(SoundRenderer::getInstance().runningThreaded() == true) {
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,SOUND_THREAD_UPDATE_MILLISECONDS);
soundThreadManager->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str());
soundThreadManager->setUniqueID(mutexOwnerId);
soundThreadManager->start();
}
}

View File

@ -544,8 +544,9 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
ftpClientThread->start();
}
// Start http meta data thread
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
modHttpServerThread = new SimpleTaskThread(this,0,200);
modHttpServerThread->setUniqueID(__FILE__);
modHttpServerThread->setUniqueID(mutexOwnerId);
modHttpServerThread->start();
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -705,8 +705,9 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
GraphicComponent::applyAllCustomProperties(containerName);
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
publishToMasterserverThread = new SimpleTaskThread(this,0,200);
publishToMasterserverThread->setUniqueID(__FILE__);
publishToMasterserverThread->setUniqueID(mutexOwnerId);
publishToMasterserverThread->start();
if(openNetworkSlots==true){

View File

@ -270,8 +270,10 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
chatManager.setFont3D(CoreData::getInstance().getMenuFontNormal3D());
needUpdateFromServer = true;
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
updateFromMasterserverThread = new SimpleTaskThread(this,0,100);
updateFromMasterserverThread->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str());
updateFromMasterserverThread->setUniqueID(mutexOwnerId);
updateFromMasterserverThread->start();
if(Config::getInstance().getString("IRCServer","") != "") {

View File

@ -250,8 +250,9 @@ MenuStateMods::MenuStateMods(Program *program, MainMenu *mainMenu) :
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Start http meta data thread
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
modHttpServerThread = new SimpleTaskThread(this,0,200);
modHttpServerThread->setUniqueID(__FILE__);
modHttpServerThread->setUniqueID(mutexOwnerId);
modHttpServerThread->start();
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -934,8 +934,9 @@ void ClientInterface::updateKeyframe(int frameCount) {
}
else {
if(networkCommandListThread == NULL) {
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
networkCommandListThread = new SimpleTaskThread(this,0,0);
networkCommandListThread->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str());
networkCommandListThread->setUniqueID(mutexOwnerId);
networkCommandListThread->start();
}

View File

@ -275,8 +275,9 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
this->setSocket(NULL);
this->slotThreadWorker = NULL;
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,playerIndex);
this->slotThreadWorker->setUniqueID(__FILE__);
this->slotThreadWorker->setUniqueID(mutexOwnerId);
this->slotThreadWorker->start();
this->ready = false;

View File

@ -205,8 +205,9 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() {
if(publishToMasterserverThread == NULL) {
if(needToRepublishToMasterserver == true || GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
publishToMasterserverThread = new SimpleTaskThread(this,0,125);
publishToMasterserverThread->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str());
publishToMasterserverThread->setUniqueID(mutexOwnerId);
publishToMasterserverThread->start();
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver);
@ -2135,8 +2136,9 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
if(publishToMasterserverThread == NULL) {
if(needToRepublishToMasterserver == true || GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
publishToMasterserverThread = new SimpleTaskThread(this,0,125);
publishToMasterserverThread->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str());
publishToMasterserverThread->setUniqueID(mutexOwnerId);
publishToMasterserverThread->start();
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver);

View File

@ -614,8 +614,9 @@ void Faction::init(
}
workerThread = NULL;
}
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
this->workerThread = new FactionThread(this);
this->workerThread->setUniqueID(__FILE__);
this->workerThread->setUniqueID(mutexOwnerId);
this->workerThread->start();
}

View File

@ -50,16 +50,26 @@ BaseThread::~BaseThread() {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
MutexSafeWrapper safeMutexMasterList(&mutexMasterThreadList);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
if(masterThreadList.find(this) == masterThreadList.end()) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
char szBuf[8096]="";
snprintf(szBuf,8096,"invalid thread delete for ptr: %p",this);
throw megaglest_runtime_error(szBuf);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
masterThreadList[this]--;
if(masterThreadList[this] <= 0) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
masterThreadList.erase(this);
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
safeMutexMasterList.ReleaseLock();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
}
bool BaseThread::isThreadDeleted(void *ptr) {

View File

@ -134,7 +134,8 @@ void FileCRCPreCacheThread::execute() {
new FileCRCPreCacheThread(techDataPaths,
workerTechList,
this->processTechCB);
workerThread->setUniqueID(__FILE__);
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
workerThread->setUniqueID(mutexOwnerId);
preCacheWorkerThreadList.push_back(workerThread);
workerThread->start();
@ -368,8 +369,8 @@ SimpleTaskThread::~SimpleTaskThread() {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
//throw megaglest_runtime_error(ex.what());
abort();
throw megaglest_runtime_error(ex.what());
//abort();
}
}

View File

@ -1791,8 +1791,9 @@ void ClientSocket::startBroadCastClientThread(DiscoveredServersInterface *cb) {
ClientSocket::stopBroadCastClientThread();
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
broadCastClientThread = new BroadCastClientSocketThread(cb);
broadCastClientThread->setUniqueID(string(__FILE__) + string("_") + string(__FUNCTION__));
broadCastClientThread->setUniqueID(mutexOwnerId);
broadCastClientThread->start();
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -2151,7 +2152,8 @@ void ServerSocket::startBroadCastThread() {
//printf("Start broadcast thread [%p]\n",broadCastThread);
broadCastThread->setUniqueID(string(__FILE__) + string("_") + string(__FUNCTION__));
static string mutexOwnerId = string(extractFileFromDirectoryPath(__FILE__).c_str()) + string("_") + intToStr(__LINE__);
broadCastThread->setUniqueID(mutexOwnerId);
broadCastThread->start();
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);