- bugfixes, some related to things pointed out by valgrind, some from opengl research and some for more stable operation

This commit is contained in:
Mark Vejvoda 2011-02-12 07:34:32 +00:00
parent d056486ec4
commit cc973f3427
13 changed files with 238 additions and 96 deletions

View File

@ -196,6 +196,32 @@ Renderer::Renderer() {
saveScreenShotThread->start(); saveScreenShotThread->start();
} }
void Renderer::cleanupScreenshotThread() {
if(saveScreenShotThread) {
saveScreenShotThread->signalQuit();
for(time_t elapsed = time(NULL);
getSaveScreenQueueSize() > 0 && difftime(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(getSaveScreenQueueSize() > 0) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] FORCING MEMORY CLEANUP and NOT SAVING screenshots, saveScreenQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,saveScreenQueue.size());
for(std::list<std::pair<string,Pixmap2D *> >::iterator iter = saveScreenQueue.begin();
iter != saveScreenQueue.end(); ++iter) {
delete iter->second;
}
saveScreenQueue.clear();
}
}
}
Renderer::~Renderer() { Renderer::~Renderer() {
delete modelRenderer; delete modelRenderer;
modelRenderer = NULL; modelRenderer = NULL;
@ -217,21 +243,7 @@ Renderer::~Renderer() {
} }
// Wait for the queue to become empty or timeout the thread at 7 seconds // Wait for the queue to become empty or timeout the thread at 7 seconds
for(time_t elapsed = time(NULL); cleanupScreenshotThread();
getSaveScreenQueueSize() > 0 && difftime(time(NULL),elapsed) <= 7;) {
sleep(10);
}
delete saveScreenShotThread;
saveScreenShotThread = NULL;
if(getSaveScreenQueueSize() > 0) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] FORCING MEMORY CLEANUP and NOT SAVING screenshots, saveScreenQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,saveScreenQueue.size());
for(std::list<std::pair<string,Pixmap2D *> >::iterator iter = saveScreenQueue.begin();
iter != saveScreenQueue.end(); ++iter) {
delete iter->second;
}
}
mapSurfaceData.clear(); mapSurfaceData.clear();
this->menu = NULL; this->menu = NULL;
@ -242,7 +254,8 @@ void Renderer::simpleTask(BaseThread *callingThread) {
// This code reads pixmaps from a queue and saves them to disk // This code reads pixmaps from a queue and saves them to disk
Pixmap2D *savePixMapBuffer=NULL; Pixmap2D *savePixMapBuffer=NULL;
string path=""; string path="";
MutexSafeWrapper safeMutex(&saveScreenShotThreadAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&saveScreenShotThreadAccessor,mutexOwnerId);
if(saveScreenQueue.size() > 0) { if(saveScreenQueue.size() > 0) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] saveScreenQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,saveScreenQueue.size()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] saveScreenQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,saveScreenQueue.size());
@ -426,6 +439,11 @@ void Renderer::end() {
std::map<string,Texture2D *> &crcFactionPreviewTextureCache = CacheManager::getCachedItem< std::map<string,Texture2D *> >(GameConstants::factionPreviewTextureCacheLookupKey); std::map<string,Texture2D *> &crcFactionPreviewTextureCache = CacheManager::getCachedItem< std::map<string,Texture2D *> >(GameConstants::factionPreviewTextureCacheLookupKey);
crcFactionPreviewTextureCache.clear(); crcFactionPreviewTextureCache.clear();
// Wait for the queue to become empty or timeout the thread at 7 seconds
cleanupScreenshotThread();
mapSurfaceData.clear();
//delete resources //delete resources
modelManager[rsGlobal]->end(); modelManager[rsGlobal]->end();
textureManager[rsGlobal]->end(); textureManager[rsGlobal]->end();
@ -434,8 +452,6 @@ void Renderer::end() {
//delete 2d list //delete 2d list
glDeleteLists(list2d, 1); glDeleteLists(list2d, 1);
mapSurfaceData.clear();
} }
void Renderer::endGame() { void Renderer::endGame() {

View File

@ -477,6 +477,8 @@ private:
//static //static
static Texture2D::Filter strToTextureFilter(const string &s); static Texture2D::Filter strToTextureFilter(const string &s);
void cleanupScreenshotThread();
}; };
}} //end namespace }} //end namespace

View File

@ -127,6 +127,14 @@ enum GAME_ARG_TYPE {
string runtimeErrorMsg = ""; string runtimeErrorMsg = "";
static void cleanupProcessObjects() {
showCursor(true);
restoreVideoMode(true);
Renderer::getInstance().end();
SystemFlags::Close();
SystemFlags::SHUTDOWN_PROGRAM_MODE=true;
}
#if defined(WIN32) && !defined(_DEBUG) && !defined(__GNUC__) #if defined(WIN32) && !defined(_DEBUG) && !defined(__GNUC__)
void fatal(const char *s, ...) // failure exit void fatal(const char *s, ...) // failure exit
{ {
@ -205,7 +213,6 @@ public:
Program *program = Program::getInstance(); Program *program = Program::getInstance();
if(program && gameInitialized == true) { if(program && gameInitialized == true) {
//SystemFlags::Close();
program->showMessage(msg.c_str()); program->showMessage(msg.c_str());
} }
@ -360,7 +367,6 @@ public:
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%s]\n",__FILE__,__FUNCTION__,__LINE__,errMsg.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%s]\n",__FILE__,__FUNCTION__,__LINE__,errMsg.c_str());
if(program && gameInitialized == true) { if(program && gameInitialized == true) {
//SystemFlags::Close();
//printf("\nprogram->getState() [%p]\n",program->getState()); //printf("\nprogram->getState() [%p]\n",program->getState());
if(program->getState() != NULL) { if(program->getState() != NULL) {
program->showMessage(errMsg.c_str()); program->showMessage(errMsg.c_str());
@ -396,19 +402,18 @@ public:
program = NULL; program = NULL;
// END // END
#ifdef WIN32
showCursor(true); showCursor(true);
restoreVideoMode(true); restoreVideoMode(true);
#ifdef WIN32
runtimeErrorMsg = errMsg; runtimeErrorMsg = errMsg;
throw runtimeErrorMsg; throw runtimeErrorMsg;
#endif #endif
//SystemFlags::Close();
//printf("In [%s::%s Line: %d] [%s] gameInitialized = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,gameInitialized); //printf("In [%s::%s Line: %d] [%s] gameInitialized = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,gameInitialized);
exit(0); cleanupProcessObjects();
exit(-1);
} }
static int DisplayMessage(const char *msg, bool exitApp) { static int DisplayMessage(const char *msg, bool exitApp) {
@ -423,8 +428,6 @@ public:
} }
if(exitApp == true) { if(exitApp == true) {
showCursor(true);
restoreVideoMode(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg); SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg);
// Now try to shutdown threads if possible // Now try to shutdown threads if possible
@ -433,7 +436,8 @@ public:
program = NULL; program = NULL;
// END // END
exit(0); cleanupProcessObjects();
exit(-1);
} }
return 0; return 0;
@ -1760,6 +1764,9 @@ int glestMain(int argc, char** argv) {
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
showCursor(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
catch(const exception &e){ catch(const exception &e){
ExceptionHandler::handleRuntimeError(e.what()); ExceptionHandler::handleRuntimeError(e.what());
@ -1781,8 +1788,8 @@ int glestMain(int argc, char** argv) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
showCursor(true); //showCursor(true);
restoreVideoMode(true); //restoreVideoMode(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1790,8 +1797,6 @@ int glestMain(int argc, char** argv) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::Close();
return 0; return 0;
} }
@ -1808,7 +1813,10 @@ __try {
//signal(SIGPIPE, SIG_IGN); //signal(SIGPIPE, SIG_IGN);
#endif #endif
return glestMain(argc, argv); int result = glestMain(argc, argv);
cleanupProcessObjects();
return result;
#ifdef WIN32_STACK_TRACE #ifdef WIN32_STACK_TRACE
} __except(stackdumper(0, GetExceptionInformation()), EXCEPTION_CONTINUE_SEARCH) { return 0; } } __except(stackdumper(0, GetExceptionInformation()), EXCEPTION_CONTINUE_SEARCH) { return 0; }

View File

@ -644,8 +644,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
PlayNow(); PlayNow();
return;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) { else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) {
RestoreLastGameSettings(); RestoreLastGameSettings();
@ -1137,22 +1137,14 @@ void MenuStateCustomGame::PlayNow() {
lastNetworkPing = time(NULL); lastNetworkPing = time(NULL);
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
/*
if(publishToMasterserverThread != NULL &&
publishToMasterserverThread->canShutdown() == true &&
publishToMasterserverThread->shutdownAndWait() == true) {
publishToMasterserverThread->setThreadOwnerValid(false);
delete publishToMasterserverThread;
publishToMasterserverThread = NULL;
}
*/
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
assert(program != NULL); assert(program != NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
cleanup(); cleanup();
program->setState(new Game(program, &gameSettings)); Game *newGame = new Game(program, &gameSettings);
program->setState(newGame);
return; return;
} }
else { else {
@ -1788,6 +1780,7 @@ void MenuStateCustomGame::update() {
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
RestoreLastGameSettings(); RestoreLastGameSettings();
PlayNow(); PlayNow();
return;
} }
} }
catch(const std::exception &ex) { catch(const std::exception &ex) {

View File

@ -61,7 +61,8 @@ void ConnectionSlotThread::signalUpdate(ConnectionSlotEvent *event) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] event = %p\n",__FILE__,__FUNCTION__,__LINE__,event); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] event = %p\n",__FILE__,__FUNCTION__,__LINE__,event);
if(event != NULL) { if(event != NULL) {
MutexSafeWrapper safeMutex(&triggerIdMutex,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
eventList.push_back(*event); eventList.push_back(*event);
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
} }
@ -73,7 +74,8 @@ void ConnectionSlotThread::setTaskCompleted(int eventId) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
if(eventId > 0) { if(eventId > 0) {
MutexSafeWrapper safeMutex(&triggerIdMutex,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
//event->eventCompleted = true; //event->eventCompleted = true;
for(int i = 0; i < eventList.size(); ++i) { for(int i = 0; i < eventList.size(); ++i) {
ConnectionSlotEvent &slotEvent = eventList[i]; ConnectionSlotEvent &slotEvent = eventList[i];
@ -90,13 +92,15 @@ void ConnectionSlotThread::setTaskCompleted(int eventId) {
} }
void ConnectionSlotThread::purgeAllEvents() { void ConnectionSlotThread::purgeAllEvents() {
MutexSafeWrapper safeMutex(&triggerIdMutex,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
eventList.clear(); eventList.clear();
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
} }
void ConnectionSlotThread::setAllEventsCompleted() { void ConnectionSlotThread::setAllEventsCompleted() {
MutexSafeWrapper safeMutex(&triggerIdMutex,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
for(int i = 0; i < eventList.size(); ++i) { for(int i = 0; i < eventList.size(); ++i) {
ConnectionSlotEvent &slotEvent = eventList[i]; ConnectionSlotEvent &slotEvent = eventList[i];
if(slotEvent.eventCompleted == false) { if(slotEvent.eventCompleted == false) {
@ -107,7 +111,8 @@ void ConnectionSlotThread::setAllEventsCompleted() {
} }
void ConnectionSlotThread::purgeCompletedEvents() { void ConnectionSlotThread::purgeCompletedEvents() {
MutexSafeWrapper safeMutex(&triggerIdMutex,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
//event->eventCompleted = true; //event->eventCompleted = true;
for(int i = eventList.size() - 1; i >= 0; i--) { for(int i = eventList.size() - 1; i >= 0; i--) {
ConnectionSlotEvent &slotEvent = eventList[i]; ConnectionSlotEvent &slotEvent = eventList[i];
@ -130,7 +135,8 @@ bool ConnectionSlotThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
bool ConnectionSlotThread::isSignalCompleted(ConnectionSlotEvent *event) { bool ConnectionSlotThread::isSignalCompleted(ConnectionSlotEvent *event) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] slotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] slotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,slotIndex);
MutexSafeWrapper safeMutex(&triggerIdMutex,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
//bool result = (event != NULL ? event->eventCompleted : true); //bool result = (event != NULL ? event->eventCompleted : true);
bool result = false; bool result = false;
if(event != NULL) { if(event != NULL) {
@ -172,7 +178,8 @@ void ConnectionSlotThread::execute() {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
int eventCount = eventList.size(); int eventCount = eventList.size();
if(eventCount > 0) { if(eventCount > 0) {
ConnectionSlotEvent eventCopy; ConnectionSlotEvent eventCopy;
@ -333,7 +340,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,mutexOwnerId);
this->vctPendingNetworkCommandList.clear(); this->vctPendingNetworkCommandList.clear();
safeMutexSlot.ReleaseLock(); safeMutexSlot.ReleaseLock();
@ -469,7 +477,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
lastReceiveCommandListTime = time(NULL); lastReceiveCommandListTime = time(NULL);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount);
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,mutexOwnerId);
for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) { for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) {
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i)); vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
} }
@ -725,7 +734,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
if(gotIntro == true) { if(gotIntro == true) {
SwitchSetupRequest switchSetupRequest; SwitchSetupRequest switchSetupRequest;
if(receiveMessage(&switchSetupRequest)) { if(receiveMessage(&switchSetupRequest)) {
MutexSafeWrapper safeMutex(getServerSynchAccessor(),string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(getServerSynchAccessor(),mutexOwnerId);
int factionIdx = switchSetupRequest.getCurrentFactionIndex(); int factionIdx = switchSetupRequest.getCurrentFactionIndex();
if(serverInterface->getSwitchSetupRequests()[factionIdx] == NULL) { if(serverInterface->getSwitchSetupRequests()[factionIdx] == NULL) {
@ -860,7 +870,8 @@ bool ConnectionSlot::updateCompleted(ConnectionSlotEvent *event) {
} }
void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) { void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) {
MutexSafeWrapper safeMutex(&socketSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&socketSynchAccessor,mutexOwnerId);
NetworkInterface::sendMessage(networkMessage); NetworkInterface::sendMessage(networkMessage);
} }
@ -869,7 +880,8 @@ string ConnectionSlot::getHumanPlayerName(int index) {
} }
vector<NetworkCommand> ConnectionSlot::getPendingNetworkCommandList(bool clearList) { vector<NetworkCommand> ConnectionSlot::getPendingNetworkCommandList(bool clearList) {
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,mutexOwnerId);
vector<NetworkCommand> ret = vctPendingNetworkCommandList; vector<NetworkCommand> ret = vctPendingNetworkCommandList;
if(clearList == true) { if(clearList == true) {
vctPendingNetworkCommandList.clear(); vctPendingNetworkCommandList.clear();
@ -880,7 +892,8 @@ vector<NetworkCommand> ConnectionSlot::getPendingNetworkCommandList(bool clearLi
} }
void ConnectionSlot::clearPendingNetworkCommandList() { void ConnectionSlot::clearPendingNetworkCommandList() {
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,mutexOwnerId);
vctPendingNetworkCommandList.clear(); vctPendingNetworkCommandList.clear();
} }

View File

@ -101,6 +101,17 @@ Map::Map() {
cells= NULL; cells= NULL;
surfaceCells= NULL; surfaceCells= NULL;
startLocations= NULL; startLocations= NULL;
title="";
waterLevel=0;
heightFactor=0;
cliffLevel=0;
w=0;
h=0;
surfaceW=0;
surfaceH=0;
maxPlayers=0;
maxMapHeight=0;
} }
Map::~Map() { Map::~Map() {

View File

@ -39,17 +39,25 @@ Minimap::Minimap() {
} }
void Minimap::init(int w, int h, const World *world, bool fogOfWar) { void Minimap::init(int w, int h, const World *world, bool fogOfWar) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
int scaledW= w/Map::cellScale; int scaledW= w/Map::cellScale;
int scaledH= h/Map::cellScale; int scaledH= h/Map::cellScale;
int potW = next2Power(scaledW);
int potH = next2Power(scaledH);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scaledW = %d, scaledH = %d, potW = %d, potH = %d\n",__FILE__,__FUNCTION__,__LINE__,scaledW,scaledH,potW,potH);
this->fogOfWar = fogOfWar; this->fogOfWar = fogOfWar;
this->gameSettings = world->getGameSettings(); this->gameSettings = world->getGameSettings();
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//fow pixmaps //fow pixmaps
float f= 0.f; float f= 0.f;
fowPixmap0= new Pixmap2D(next2Power(scaledW), next2Power(scaledH), 1); fowPixmap0= new Pixmap2D(potW, potH, 1);
fowPixmap1= new Pixmap2D(next2Power(scaledW), next2Power(scaledH), 1); fowPixmap1= new Pixmap2D(potW, potH, 1);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
fowPixmap0->setPixels(&f); fowPixmap0->setPixels(&f);
if((this->gameSettings->getFlagTypes1() & ft1_show_map_resources) == ft1_show_map_resources) { if((this->gameSettings->getFlagTypes1() & ft1_show_map_resources) == ft1_show_map_resources) {
@ -66,26 +74,37 @@ void Minimap::init(int w, int h, const World *world, bool fogOfWar) {
fowPixmap1->setPixels(&f); fowPixmap1->setPixels(&f);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//fow tex //fow tex
fowTex= renderer.newTexture2D(rsGame); fowTex= renderer.newTexture2D(rsGame);
fowTex->setMipmap(false); fowTex->setMipmap(false);
fowTex->setPixmapInit(false); fowTex->setPixmapInit(false);
fowTex->setFormat(Texture::fAlpha); fowTex->setFormat(Texture::fAlpha);
fowTex->getPixmap()->init(next2Power(scaledW), next2Power(scaledH), 1);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scaledW = %d, scaledH = %d, potW = %d, potH = %d\n",__FILE__,__FUNCTION__,__LINE__,scaledW,scaledH,potW,potH);
fowTex->getPixmap()->init(potW, potH, 1);
fowTex->getPixmap()->setPixels(&f); fowTex->getPixmap()->setPixels(&f);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//tex //tex
tex= renderer.newTexture2D(rsGame); tex= renderer.newTexture2D(rsGame);
tex->getPixmap()->init(scaledW, scaledH, 3); tex->getPixmap()->init(scaledW, scaledH, 3);
tex->setMipmap(false); tex->setMipmap(false);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
computeTexture(world); computeTexture(world);
} }
Minimap::~Minimap() { Minimap::~Minimap() {
Logger::getInstance().add("Minimap", true); Logger::getInstance().add("Minimap", true);
delete fowPixmap0; delete fowPixmap0;
fowPixmap0=NULL;
delete fowPixmap1; delete fowPixmap1;
fowPixmap1=NULL;
} }
// ==================== set ==================== // ==================== set ====================

View File

@ -120,6 +120,7 @@ public:
static int DEFAULT_HTTP_TIMEOUT; static int DEFAULT_HTTP_TIMEOUT;
static bool VERBOSE_MODE_ENABLED; static bool VERBOSE_MODE_ENABLED;
static bool ENABLE_THREADED_LOGGING; static bool ENABLE_THREADED_LOGGING;
static bool SHUTDOWN_PROGRAM_MODE;
SystemFlags(); SystemFlags();
~SystemFlags(); ~SystemFlags();

View File

@ -790,17 +790,27 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
/*
* Replaced this call due to: http://www.opengl.org/wiki/Common_Mistakes#gluBuild2DMipmaps
*
int error= gluBuild2DMipmaps( int error= gluBuild2DMipmaps(
GL_TEXTURE_2D, glCompressionFormat, GL_TEXTURE_2D, glCompressionFormat,
pixmap.getW(), pixmap.getH(), pixmap.getW(), pixmap.getH(),
glFormat, GL_UNSIGNED_BYTE, pixels); glFormat, GL_UNSIGNED_BYTE, pixels);
*/
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, glCompressionFormat,
pixmap.getW(), pixmap.getH(), 0,
glFormat, GL_UNSIGNED_BYTE, pixels);
GLint error= glGetError();
if(error != 0) { if(error != 0) {
//throw runtime_error("Error building texture 2D mipmaps"); //throw runtime_error("Error building texture 2D mipmaps");
char szBuf[1024]=""; char szBuf[1024]="";
sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d, glCompressionFormat = %d",error,(pixmap.getPath() != "" ? pixmap.getPath().c_str() : this->path.c_str()),pixmap.getW(),pixmap.getH(),glCompressionFormat); sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d, glCompressionFormat = %d",error,(pixmap.getPath() != "" ? pixmap.getPath().c_str() : this->path.c_str()),pixmap.getW(),pixmap.getH(),glCompressionFormat);
throw runtime_error(szBuf); throw runtime_error(szBuf);
} }
} }
else { else {
//build single texture //build single texture
@ -965,17 +975,30 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy) {
GLenum target= GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; GLenum target= GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
if(mipmap) { if(mipmap) {
/*
* Replaced this call due to: http://www.opengl.org/wiki/Common_Mistakes#gluBuild2DMipmaps
*
int error= gluBuild2DMipmaps( int error= gluBuild2DMipmaps(
target, glCompressionFormat, target, glCompressionFormat,
currentPixmap->getW(), currentPixmap->getH(), currentPixmap->getW(), currentPixmap->getH(),
glFormat, GL_UNSIGNED_BYTE, pixels); glFormat, GL_UNSIGNED_BYTE, pixels);
*/
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(target, 0, glCompressionFormat,
currentPixmap->getW(), currentPixmap->getH(), 0,
glFormat, GL_UNSIGNED_BYTE, pixels);
int error = glGetError();
if(error != 0) { if(error != 0) {
//throw runtime_error("Error building texture cube mipmaps"); //throw runtime_error("Error building texture cube mipmaps");
char szBuf[1024]=""; char szBuf[1024]="";
sprintf(szBuf,"Error building texture cube mipmaps, returned: %d [%s] w = %d, h = %d, glCompressionFormat = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH(),glCompressionFormat); sprintf(szBuf,"Error building texture cube mipmaps, returned: %d [%s] w = %d, h = %d, glCompressionFormat = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH(),glCompressionFormat);
throw runtime_error(szBuf); throw runtime_error(szBuf);
} }
} }
else { else {
glTexImage2D( glTexImage2D(

View File

@ -691,10 +691,20 @@ Pixmap2D::Pixmap2D() {
} }
Pixmap2D::Pixmap2D(int components) { Pixmap2D::Pixmap2D(int components) {
h= -1;
w= -1;
this->components= -1;
pixels= NULL;
init(components); init(components);
} }
Pixmap2D::Pixmap2D(int w, int h, int components) { Pixmap2D::Pixmap2D(int w, int h, int components) {
this->h= 0;
this->w= -1;
this->components= -1;
pixels= NULL;
init(w, h, components); init(w, h, components);
} }
@ -702,6 +712,7 @@ void Pixmap2D::init(int components) {
this->w= -1; this->w= -1;
this->h= -1; this->h= -1;
this->components= components; this->components= components;
deletePixels();
pixels= NULL; pixels= NULL;
} }
@ -709,7 +720,16 @@ void Pixmap2D::init(int w, int h, int components) {
this->w= w; this->w= w;
this->h= h; this->h= h;
this->components= components; this->components= components;
deletePixels();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] w = %d, h = %d, components = %d, getPixelByteCount() = %llu\n",__FILE__,__FUNCTION__,__LINE__,w,h,components,(long long unsigned)getPixelByteCount());
if(getPixelByteCount() <= 0 || (h <= 0 || w <= 0 || components <= 0)) {
char szBuf[1024];
sprintf(szBuf,"Invalid pixmap dimensions for [%s], h = %d, w = %d, components = %d\n",path.c_str(),h,w,components);
throw runtime_error(szBuf);
}
pixels= new uint8[(std::size_t)getPixelByteCount()]; pixels= new uint8[(std::size_t)getPixelByteCount()];
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
uint64 Pixmap2D::getPixelByteCount() const { uint64 Pixmap2D::getPixelByteCount() const {
@ -717,8 +737,12 @@ uint64 Pixmap2D::getPixelByteCount() const {
} }
void Pixmap2D::deletePixels() { void Pixmap2D::deletePixels() {
delete [] pixels; if(pixels) {
pixels = NULL; //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete [] pixels;
pixels = NULL;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
} }
Pixmap2D::~Pixmap2D() { Pixmap2D::~Pixmap2D() {
@ -726,7 +750,7 @@ Pixmap2D::~Pixmap2D() {
} }
Pixmap2D* Pixmap2D::loadPath(const string& path) { Pixmap2D* Pixmap2D::loadPath(const string& path) {
printf("Loading Pixmap2D [%s]\n",path.c_str()); //printf("Loading Pixmap2D [%s]\n",path.c_str());
Pixmap2D *pixmap = FileReader<Pixmap2D>::readPath(path); Pixmap2D *pixmap = FileReader<Pixmap2D>::readPath(path);
if(pixmap != NULL) { if(pixmap != NULL) {

View File

@ -49,14 +49,16 @@ Mutex * BaseThread::getMutexThreadOwnerValid() {
} }
void BaseThread::setThreadOwnerValid(bool value) { void BaseThread::setThreadOwnerValid(bool value) {
MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,mutexOwnerId);
threadOwnerValid = value; threadOwnerValid = value;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
} }
bool BaseThread::getThreadOwnerValid() { bool BaseThread::getThreadOwnerValid() {
bool ret = false; bool ret = false;
MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,mutexOwnerId);
ret = threadOwnerValid; ret = threadOwnerValid;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -64,17 +66,18 @@ bool BaseThread::getThreadOwnerValid() {
} }
void BaseThread::signalQuit() { void BaseThread::signalQuit() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str()); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
setQuitStatus(true); setQuitStatus(true);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str()); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
} }
void BaseThread::setQuitStatus(bool value) { void BaseThread::setQuitStatus(bool value) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
MutexSafeWrapper safeMutex(&mutexQuit,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexQuit,mutexOwnerId);
quit = value; quit = value;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -85,7 +88,8 @@ bool BaseThread::getQuitStatus() {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool retval = false; bool retval = false;
MutexSafeWrapper safeMutex(&mutexQuit,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexQuit,mutexOwnerId);
retval = quit; retval = quit;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -96,7 +100,8 @@ bool BaseThread::getQuitStatus() {
bool BaseThread::getHasBeginExecution() { bool BaseThread::getHasBeginExecution() {
bool retval = false; bool retval = false;
MutexSafeWrapper safeMutex(&mutexBeginExecution,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexBeginExecution,mutexOwnerId);
retval = hasBeginExecution; retval = hasBeginExecution;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -108,7 +113,8 @@ bool BaseThread::getHasBeginExecution() {
void BaseThread::setHasBeginExecution(bool value) { void BaseThread::setHasBeginExecution(bool value) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
MutexSafeWrapper safeMutex(&mutexBeginExecution,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexBeginExecution,mutexOwnerId);
hasBeginExecution = value; hasBeginExecution = value;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -119,7 +125,9 @@ bool BaseThread::getRunningStatus() {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str()); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
bool retval = false; bool retval = false;
MutexSafeWrapper safeMutex(&mutexRunning,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexRunning,mutexOwnerId);
retval = running; retval = running;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -133,25 +141,30 @@ bool BaseThread::getRunningStatus() {
} }
void BaseThread::setRunningStatus(bool value) { void BaseThread::setRunningStatus(bool value) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] value = %d\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),value); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] value = %d\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),value);
MutexSafeWrapper safeMutex(&mutexRunning,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexRunning,mutexOwnerId);
running = value; running = value;
setHasBeginExecution(true); if(value == true) {
setHasBeginExecution(true);
}
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str()); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
} }
void BaseThread::setExecutingTask(bool value) { void BaseThread::setExecutingTask(bool value) {
MutexSafeWrapper safeMutex(&mutexExecutingTask,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexExecutingTask,mutexOwnerId);
executingTask = value; executingTask = value;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
} }
bool BaseThread::getExecutingTask() { bool BaseThread::getExecutingTask() {
bool retval = false; bool retval = false;
MutexSafeWrapper safeMutex(&mutexExecutingTask,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexExecutingTask,mutexOwnerId);
retval = executingTask; retval = executingTask;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -160,7 +173,8 @@ bool BaseThread::getExecutingTask() {
bool BaseThread::getDeleteSelfOnExecutionDone() { bool BaseThread::getDeleteSelfOnExecutionDone() {
bool retval = false; bool retval = false;
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,mutexOwnerId);
retval = deleteSelfOnExecutionDone; retval = deleteSelfOnExecutionDone;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -168,7 +182,8 @@ bool BaseThread::getDeleteSelfOnExecutionDone() {
} }
void BaseThread::setDeleteSelfOnExecutionDone(bool value) { void BaseThread::setDeleteSelfOnExecutionDone(bool value) {
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,mutexOwnerId);
deleteSelfOnExecutionDone = value; deleteSelfOnExecutionDone = value;
} }
@ -218,14 +233,11 @@ bool BaseThread::shutdownAndWait() {
} }
sleep(0); sleep(0);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
//sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
sleep(0); sleep(0);
} }
} }
//sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
return ret; return ret;
} }

View File

@ -87,13 +87,15 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter
this->needTaskSignal = needTaskSignal; this->needTaskSignal = needTaskSignal;
setTaskSignalled(false); setTaskSignalled(false);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId);
lastExecuteTimestamp = time(NULL); lastExecuteTimestamp = time(NULL);
} }
bool SimpleTaskThread::isThreadExecutionLagging() { bool SimpleTaskThread::isThreadExecutionLagging() {
bool result = false; bool result = false;
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId);
result = (difftime(time(NULL),lastExecuteTimestamp) >= 5.0); result = (difftime(time(NULL),lastExecuteTimestamp) >= 5.0);
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -111,6 +113,7 @@ bool SimpleTaskThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
} }
void SimpleTaskThread::execute() { void SimpleTaskThread::execute() {
bool mustDeleteSelf = false;
{ {
{ {
RunningStatusSafeWrapper runningStatus(this); RunningStatusSafeWrapper runningStatus(this);
@ -141,7 +144,8 @@ void SimpleTaskThread::execute() {
ExecutingTaskSafeWrapper safeExecutingTaskMutex(this); ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
this->simpleTaskInterface->simpleTask(this); this->simpleTaskInterface->simpleTask(this);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId);
lastExecuteTimestamp = time(NULL); lastExecuteTimestamp = time(NULL);
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
} }
@ -174,14 +178,19 @@ void SimpleTaskThread::execute() {
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
mustDeleteSelf = getDeleteSelfOnExecutionDone();
}
if(mustDeleteSelf == true) {
delete this;
} }
deleteSelfIfRequired();
} }
void SimpleTaskThread::setTaskSignalled(bool value) { void SimpleTaskThread::setTaskSignalled(bool value) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&mutexTaskSignaller,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexTaskSignaller,mutexOwnerId);
taskSignalled = value; taskSignalled = value;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -192,7 +201,8 @@ bool SimpleTaskThread::getTaskSignalled() {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool retval = false; bool retval = false;
MutexSafeWrapper safeMutex(&mutexTaskSignaller,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexTaskSignaller,mutexOwnerId);
retval = taskSignalled; retval = taskSignalled;
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
@ -209,7 +219,8 @@ LogFileThread::LogFileThread() : BaseThread() {
} }
void LogFileThread::addLogEntry(SystemFlags::DebugType type, string logEntry) { void LogFileThread::addLogEntry(SystemFlags::DebugType type, string logEntry) {
MutexSafeWrapper safeMutex(&mutexLogList,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLogList,mutexOwnerId);
LogFileEntry entry; LogFileEntry entry;
entry.type = type; entry.type = type;
entry.entry = logEntry; entry.entry = logEntry;
@ -233,6 +244,7 @@ bool LogFileThread::checkSaveCurrentLogBufferToDisk() {
} }
void LogFileThread::execute() { void LogFileThread::execute() {
bool mustDeleteSelf = false;
{ {
RunningStatusSafeWrapper runningStatus(this); RunningStatusSafeWrapper runningStatus(this);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -270,19 +282,25 @@ void LogFileThread::execute() {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
mustDeleteSelf = getDeleteSelfOnExecutionDone();
}
if(mustDeleteSelf == true) {
delete this;
} }
deleteSelfIfRequired();
} }
std::size_t LogFileThread::getLogEntryBufferCount() { std::size_t LogFileThread::getLogEntryBufferCount() {
MutexSafeWrapper safeMutex(&mutexLogList,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLogList,mutexOwnerId);
std::size_t logCount = logList.size(); std::size_t logCount = logList.size();
safeMutex.ReleaseLock(); safeMutex.ReleaseLock();
return logCount; return logCount;
} }
void LogFileThread::saveToDisk(bool forceSaveAll,bool logListAlreadyLocked) { void LogFileThread::saveToDisk(bool forceSaveAll,bool logListAlreadyLocked) {
MutexSafeWrapper safeMutex(NULL,string(__FILE__) + "_" + intToStr(__LINE__)); static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(NULL,mutexOwnerId);
if(logListAlreadyLocked == false) { if(logListAlreadyLocked == false) {
safeMutex.setMutex(&mutexLogList); safeMutex.setMutex(&mutexLogList);
} }

View File

@ -50,6 +50,7 @@ int SystemFlags::DEFAULT_HTTP_TIMEOUT = 10;
bool SystemFlags::VERBOSE_MODE_ENABLED = false; bool SystemFlags::VERBOSE_MODE_ENABLED = false;
bool SystemFlags::ENABLE_THREADED_LOGGING = false; bool SystemFlags::ENABLE_THREADED_LOGGING = false;
static LogFileThread *threadLogger = NULL; static LogFileThread *threadLogger = NULL;
bool SystemFlags::SHUTDOWN_PROGRAM_MODE = false;
// //
static void *myrealloc(void *ptr, size_t size) static void *myrealloc(void *ptr, size_t size)
@ -197,10 +198,10 @@ void SystemFlags::init(bool haveSpecialOutputCommandLineOption) {
(*SystemFlags::debugLogFileList)[SystemFlags::debugError] = SystemFlags::SystemFlagsType(SystemFlags::debugError); (*SystemFlags::debugLogFileList)[SystemFlags::debugError] = SystemFlags::SystemFlagsType(SystemFlags::debugError);
} }
if(threadLogger == NULL) { if(threadLogger == NULL && SystemFlags::SHUTDOWN_PROGRAM_MODE == false) {
threadLogger = new LogFileThread(); threadLogger = new LogFileThread();
threadLogger->start(); threadLogger->start();
sleep(5); sleep(1);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -261,6 +262,7 @@ SystemFlags::~SystemFlags() {
void SystemFlags::Close() { void SystemFlags::Close() {
if(threadLogger != NULL) { if(threadLogger != NULL) {
SystemFlags::ENABLE_THREADED_LOGGING = false; SystemFlags::ENABLE_THREADED_LOGGING = false;
//SystemFlags::SHUTDOWN_PROGRAM_MODE=true;
threadLogger->signalQuit(); threadLogger->signalQuit();
threadLogger->shutdownAndWait(); threadLogger->shutdownAndWait();
delete threadLogger; delete threadLogger;