- 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();
}
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() {
delete modelRenderer;
modelRenderer = NULL;
@ -217,21 +243,7 @@ Renderer::~Renderer() {
}
// Wait for the queue to become empty or timeout the thread at 7 seconds
for(time_t elapsed = time(NULL);
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;
}
}
cleanupScreenshotThread();
mapSurfaceData.clear();
this->menu = NULL;
@ -242,7 +254,8 @@ void Renderer::simpleTask(BaseThread *callingThread) {
// This code reads pixmaps from a queue and saves them to disk
Pixmap2D *savePixMapBuffer=NULL;
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) {
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);
crcFactionPreviewTextureCache.clear();
// Wait for the queue to become empty or timeout the thread at 7 seconds
cleanupScreenshotThread();
mapSurfaceData.clear();
//delete resources
modelManager[rsGlobal]->end();
textureManager[rsGlobal]->end();
@ -434,8 +452,6 @@ void Renderer::end() {
//delete 2d list
glDeleteLists(list2d, 1);
mapSurfaceData.clear();
}
void Renderer::endGame() {

View File

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

View File

@ -127,6 +127,14 @@ enum GAME_ARG_TYPE {
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__)
void fatal(const char *s, ...) // failure exit
{
@ -205,7 +213,6 @@ public:
Program *program = Program::getInstance();
if(program && gameInitialized == true) {
//SystemFlags::Close();
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());
if(program && gameInitialized == true) {
//SystemFlags::Close();
//printf("\nprogram->getState() [%p]\n",program->getState());
if(program->getState() != NULL) {
program->showMessage(errMsg.c_str());
@ -396,19 +402,18 @@ public:
program = NULL;
// END
#ifdef WIN32
showCursor(true);
restoreVideoMode(true);
#ifdef WIN32
runtimeErrorMsg = errMsg;
throw runtimeErrorMsg;
#endif
//SystemFlags::Close();
//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) {
@ -423,8 +428,6 @@ public:
}
if(exitApp == true) {
showCursor(true);
restoreVideoMode(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg);
// Now try to shutdown threads if possible
@ -433,7 +436,8 @@ public:
program = NULL;
// END
exit(0);
cleanupProcessObjects();
exit(-1);
}
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__);
showCursor(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
catch(const exception &e){
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__);
showCursor(true);
restoreVideoMode(true);
//showCursor(true);
//restoreVideoMode(true);
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::Close();
return 0;
}
@ -1808,7 +1813,10 @@ __try {
//signal(SIGPIPE, SIG_IGN);
#endif
return glestMain(argc, argv);
int result = glestMain(argc, argv);
cleanupProcessObjects();
return result;
#ifdef WIN32_STACK_TRACE
} __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__);
PlayNow();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
return;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) {
RestoreLastGameSettings();
@ -1137,22 +1137,14 @@ void MenuStateCustomGame::PlayNow() {
lastNetworkPing = time(NULL);
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__);
assert(program != NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
cleanup();
program->setState(new Game(program, &gameSettings));
Game *newGame = new Game(program, &gameSettings);
program->setState(newGame);
return;
}
else {
@ -1788,6 +1780,7 @@ void MenuStateCustomGame::update() {
safeMutex.ReleaseLock();
RestoreLastGameSettings();
PlayNow();
return;
}
}
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);
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);
safeMutex.ReleaseLock();
}
@ -73,7 +74,8 @@ void ConnectionSlotThread::setTaskCompleted(int eventId) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
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;
for(int i = 0; i < eventList.size(); ++i) {
ConnectionSlotEvent &slotEvent = eventList[i];
@ -90,13 +92,15 @@ void ConnectionSlotThread::setTaskCompleted(int eventId) {
}
void ConnectionSlotThread::purgeAllEvents() {
MutexSafeWrapper safeMutex(&triggerIdMutex,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&triggerIdMutex,mutexOwnerId);
eventList.clear();
safeMutex.ReleaseLock();
}
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) {
ConnectionSlotEvent &slotEvent = eventList[i];
if(slotEvent.eventCompleted == false) {
@ -107,7 +111,8 @@ void ConnectionSlotThread::setAllEventsCompleted() {
}
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;
for(int i = eventList.size() - 1; i >= 0; i--) {
ConnectionSlotEvent &slotEvent = eventList[i];
@ -130,7 +135,8 @@ bool ConnectionSlotThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
bool ConnectionSlotThread::isSignalCompleted(ConnectionSlotEvent *event) {
//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 = false;
if(event != NULL) {
@ -172,7 +178,8 @@ void ConnectionSlotThread::execute() {
//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();
if(eventCount > 0) {
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());
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,mutexOwnerId);
this->vctPendingNetworkCommandList.clear();
safeMutexSlot.ReleaseLock();
@ -469,7 +477,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
lastReceiveCommandListTime = time(NULL);
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) {
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
}
@ -725,7 +734,8 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
if(gotIntro == true) {
SwitchSetupRequest 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();
if(serverInterface->getSwitchSetupRequests()[factionIdx] == NULL) {
@ -860,7 +870,8 @@ bool ConnectionSlot::updateCompleted(ConnectionSlotEvent *event) {
}
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);
}
@ -869,7 +880,8 @@ string ConnectionSlot::getHumanPlayerName(int index) {
}
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;
if(clearList == true) {
vctPendingNetworkCommandList.clear();
@ -880,7 +892,8 @@ vector<NetworkCommand> ConnectionSlot::getPendingNetworkCommandList(bool clearLi
}
void ConnectionSlot::clearPendingNetworkCommandList() {
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,mutexOwnerId);
vctPendingNetworkCommandList.clear();
}

View File

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

View File

@ -39,17 +39,25 @@ Minimap::Minimap() {
}
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 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->gameSettings = world->getGameSettings();
Renderer &renderer= Renderer::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//fow pixmaps
float f= 0.f;
fowPixmap0= new Pixmap2D(next2Power(scaledW), next2Power(scaledH), 1);
fowPixmap1= new Pixmap2D(next2Power(scaledW), next2Power(scaledH), 1);
fowPixmap0= new Pixmap2D(potW, potH, 1);
fowPixmap1= new Pixmap2D(potW, potH, 1);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
fowPixmap0->setPixels(&f);
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);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//fow tex
fowTex= renderer.newTexture2D(rsGame);
fowTex->setMipmap(false);
fowTex->setPixmapInit(false);
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);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//tex
tex= renderer.newTexture2D(rsGame);
tex->getPixmap()->init(scaledW, scaledH, 3);
tex->setMipmap(false);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
computeTexture(world);
}
Minimap::~Minimap() {
Logger::getInstance().add("Minimap", true);
delete fowPixmap0;
fowPixmap0=NULL;
delete fowPixmap1;
fowPixmap1=NULL;
}
// ==================== set ====================

View File

@ -120,6 +120,7 @@ public:
static int DEFAULT_HTTP_TIMEOUT;
static bool VERBOSE_MODE_ENABLED;
static bool ENABLE_THREADED_LOGGING;
static bool SHUTDOWN_PROGRAM_MODE;
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_MAG_FILTER, GL_LINEAR);
/*
* Replaced this call due to: http://www.opengl.org/wiki/Common_Mistakes#gluBuild2DMipmaps
*
int error= gluBuild2DMipmaps(
GL_TEXTURE_2D, glCompressionFormat,
pixmap.getW(), pixmap.getH(),
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) {
//throw runtime_error("Error building texture 2D mipmaps");
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);
throw runtime_error(szBuf);
}
}
else {
//build single texture
@ -965,17 +975,30 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy) {
GLenum target= GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
if(mipmap) {
/*
* Replaced this call due to: http://www.opengl.org/wiki/Common_Mistakes#gluBuild2DMipmaps
*
int error= gluBuild2DMipmaps(
target, glCompressionFormat,
currentPixmap->getW(), currentPixmap->getH(),
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) {
//throw runtime_error("Error building texture cube mipmaps");
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);
throw runtime_error(szBuf);
}
}
else {
glTexImage2D(

View File

@ -691,10 +691,20 @@ Pixmap2D::Pixmap2D() {
}
Pixmap2D::Pixmap2D(int components) {
h= -1;
w= -1;
this->components= -1;
pixels= NULL;
init(components);
}
Pixmap2D::Pixmap2D(int w, int h, int components) {
this->h= 0;
this->w= -1;
this->components= -1;
pixels= NULL;
init(w, h, components);
}
@ -702,6 +712,7 @@ void Pixmap2D::init(int components) {
this->w= -1;
this->h= -1;
this->components= components;
deletePixels();
pixels= NULL;
}
@ -709,7 +720,16 @@ void Pixmap2D::init(int w, int h, int components) {
this->w= w;
this->h= h;
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()];
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
uint64 Pixmap2D::getPixelByteCount() const {
@ -717,8 +737,12 @@ uint64 Pixmap2D::getPixelByteCount() const {
}
void Pixmap2D::deletePixels() {
delete [] pixels;
pixels = NULL;
if(pixels) {
//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() {
@ -726,7 +750,7 @@ Pixmap2D::~Pixmap2D() {
}
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);
if(pixmap != NULL) {

View File

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

View File

@ -87,13 +87,15 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter
this->needTaskSignal = needTaskSignal;
setTaskSignalled(false);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId);
lastExecuteTimestamp = time(NULL);
}
bool SimpleTaskThread::isThreadExecutionLagging() {
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);
safeMutex.ReleaseLock();
@ -111,6 +113,7 @@ bool SimpleTaskThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
}
void SimpleTaskThread::execute() {
bool mustDeleteSelf = false;
{
{
RunningStatusSafeWrapper runningStatus(this);
@ -141,7 +144,8 @@ void SimpleTaskThread::execute() {
ExecutingTaskSafeWrapper safeExecutingTaskMutex(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);
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());
mustDeleteSelf = getDeleteSelfOnExecutionDone();
}
if(mustDeleteSelf == true) {
delete this;
}
deleteSelfIfRequired();
}
void SimpleTaskThread::setTaskSignalled(bool value) {
//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;
safeMutex.ReleaseLock();
@ -192,7 +201,8 @@ bool SimpleTaskThread::getTaskSignalled() {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool retval = false;
MutexSafeWrapper safeMutex(&mutexTaskSignaller,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexTaskSignaller,mutexOwnerId);
retval = taskSignalled;
safeMutex.ReleaseLock();
@ -209,7 +219,8 @@ LogFileThread::LogFileThread() : BaseThread() {
}
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;
entry.type = type;
entry.entry = logEntry;
@ -233,6 +244,7 @@ bool LogFileThread::checkSaveCurrentLogBufferToDisk() {
}
void LogFileThread::execute() {
bool mustDeleteSelf = false;
{
RunningStatusSafeWrapper runningStatus(this);
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__);
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() {
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();
safeMutex.ReleaseLock();
return logCount;
}
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) {
safeMutex.setMutex(&mutexLogList);
}

View File

@ -50,6 +50,7 @@ int SystemFlags::DEFAULT_HTTP_TIMEOUT = 10;
bool SystemFlags::VERBOSE_MODE_ENABLED = false;
bool SystemFlags::ENABLE_THREADED_LOGGING = false;
static LogFileThread *threadLogger = NULL;
bool SystemFlags::SHUTDOWN_PROGRAM_MODE = false;
//
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);
}
if(threadLogger == NULL) {
if(threadLogger == NULL && SystemFlags::SHUTDOWN_PROGRAM_MODE == false) {
threadLogger = new LogFileThread();
threadLogger->start();
sleep(5);
sleep(1);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -261,6 +262,7 @@ SystemFlags::~SystemFlags() {
void SystemFlags::Close() {
if(threadLogger != NULL) {
SystemFlags::ENABLE_THREADED_LOGGING = false;
//SystemFlags::SHUTDOWN_PROGRAM_MODE=true;
threadLogger->signalQuit();
threadLogger->shutdownAndWait();
delete threadLogger;