- fix headless server crash due to new call to setgama in headless mode

- a few code optimizations to start to improve performance
This commit is contained in:
Mark Vejvoda
2012-04-16 06:14:10 +00:00
parent f612707849
commit a37dc8a7b3
4 changed files with 100 additions and 57 deletions

View File

@@ -6534,13 +6534,14 @@ void Renderer::loadConfig() {
if(this->program == NULL) { if(this->program == NULL) {
throw megaglest_runtime_error("this->program == NULL"); throw megaglest_runtime_error("this->program == NULL");
} }
//if(this->program != NULL) { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
if(gammaValue!=0.0){ //if(this->program != NULL) {
this->program->getWindow()->setGamma(gammaValue); if(gammaValue != 0.0) {
SDL_SetGamma(gammaValue, gammaValue, gammaValue); this->program->getWindow()->setGamma(gammaValue);
SDL_SetGamma(gammaValue, gammaValue, gammaValue);
}
//}
} }
//}
//load shadows //load shadows
shadows= strToShadows(config.getString("Shadows")); shadows= strToShadows(config.getString("Shadows"));
if(shadows==sProjected || shadows==sShadowMapping){ if(shadows==sProjected || shadows==sShadowMapping){

View File

@@ -3311,6 +3311,9 @@ void Unit::removeBadHarvestPos(const Vec2i &value) {
bool Unit::isBadHarvestPos(const Vec2i &value, bool checkPeerUnits) const { bool Unit::isBadHarvestPos(const Vec2i &value, bool checkPeerUnits) const {
bool result = false; bool result = false;
if(badHarvestPosList.empty() == true) {
return result;
}
std::map<Vec2i,int>::const_iterator iter = badHarvestPosList.find(value); std::map<Vec2i,int>::const_iterator iter = badHarvestPosList.find(value);
if(iter != badHarvestPosList.end()) { if(iter != badHarvestPosList.end()) {
@@ -3322,6 +3325,7 @@ bool Unit::isBadHarvestPos(const Vec2i &value, bool checkPeerUnits) const {
for(int i = 0; i < this->getFaction()->getUnitCount(); ++i) { for(int i = 0; i < this->getFaction()->getUnitCount(); ++i) {
Unit *peerUnit = this->getFaction()->getUnit(i); Unit *peerUnit = this->getFaction()->getUnit(i);
if( peerUnit != NULL && peerUnit->getId() != this->getId() && if( peerUnit != NULL && peerUnit->getId() != this->getId() &&
peerUnit->getType()->hasCommandClass(ccHarvest) == true &&
peerUnit->getType()->getSize() <= this->getType()->getSize()) { peerUnit->getType()->getSize() <= this->getType()->getSize()) {
if(peerUnit->isBadHarvestPos(value,false) == true) { if(peerUnit->isBadHarvestPos(value,false) == true) {
result = true; result = true;

View File

@@ -79,58 +79,94 @@ public:
} }
#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD) #if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
inline static int getFileAndLine(void *address, char *file, size_t flen) { inline static int getFileAndLine(char *function, void *address, char *file, size_t flen) {
int line=-1; int line=-1;
if(want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") { if(want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") {
const int maxbufSize = 4096; const int maxbufSize = 8094;
char buf[maxbufSize+1]=""; char buf[maxbufSize+1]="";
//char *p=NULL;
// prepare command to be executed // prepare command to be executed
// our program need to be passed after the -e parameter // our program need to be passed after the -e parameter
//sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr); //sprintf (buf, "/usr/bin/addr2line -C -e ./a.out -f -i %lx", addr);
sprintf(buf, "addr2line -C -e %s -f -i %p",AllocInfo::get_application_binary().c_str(),address); sprintf(buf, "addr2line -C -e %s -f -i %p",AllocInfo::get_application_binary().c_str(),address);
FILE* f = popen (buf, "r"); FILE* f = popen (buf, "r");
if (f == NULL) { if (f == NULL) {
perror (buf); perror (buf);
return 0; return 0;
}
// get function name
char *ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return 0;
}
// get file and line
ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return 0;
}
if(strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while(*p != 0 && *p != ':') {
p++;
} }
*p++ = 0; if(function != NULL && function[0] != '\0') {
// after file name follows line number line = 0;
strcpy (file , buf); for(;function != NULL && function[0] != '\0';) {
sscanf (p,"%d", &line); // get function name
} char *ret = fgets (buf, maxbufSize, f);
else { if(ret == NULL) {
strcpy (file,"unknown"); pclose(f);
line = 0; return line;
} }
pclose(f); //printf("Looking for [%s] Found [%s]\n",function,ret);
} if(strstr(ret,function) != NULL) {
return line; break;
}
// get file and line
ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
if(strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while(*p != 0 && *p != ':') {
p++;
}
*p++ = 0;
// after file name follows line number
strcpy (file , buf);
sscanf (p,"%d", &line);
}
else {
strcpy (file,"unknown");
line = 0;
}
}
}
// get file and line
char *ret = fgets (buf, maxbufSize, f);
if(ret == NULL) {
pclose(f);
return line;
}
if(strlen(buf) > 0 && buf[0] != '?') {
//int l;
char *p = buf;
// file name is until ':'
while(*p != 0 && *p != ':') {
p++;
}
*p++ = 0;
// after file name follows line number
strcpy (file , buf);
sscanf (p,"%d", &line);
}
else {
strcpy (file,"unknown");
line = 0;
}
pclose(f);
}
return line;
} }
#endif #endif
@@ -158,6 +194,8 @@ public:
size_t sz = 8096; // just a guess, template names will go much wider size_t sz = 8096; // just a guess, template names will go much wider
char *function = static_cast<char *>(malloc(sz)); char *function = static_cast<char *>(malloc(sz));
function[0] = '\0';
char *begin = 0; char *begin = 0;
char *end = 0; char *end = 0;
@@ -201,7 +239,7 @@ public:
if(want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") { if(want_full_leak_stacktrace_line_numbers == true && AllocInfo::get_application_binary() != "") {
char file[8096]=""; char file[8096]="";
int line = getFileAndLine(lineAddress, file, 8096); int line = getFileAndLine(function, lineAddress, file, 8096);
if(line >= 0) { if(line >= 0) {
char lineBuf[1024]=""; char lineBuf[1024]="";
sprintf(lineBuf,"%d",line); sprintf(lineBuf,"%d",line);

View File

@@ -258,13 +258,13 @@ void ReadWriteMutex::UnLockRead() {
void ReadWriteMutex::LockWrite() { void ReadWriteMutex::LockWrite() {
MutexSafeWrapper safeMutex(&mutex); MutexSafeWrapper safeMutex(&mutex);
uint32 totalLocks = maxReaders(); uint32 totalLocks = maxReaders();
for (int i = 0; i < totalLocks; ++i) { for(unsigned int i = 0; i < totalLocks; ++i) {
semaphore.waitTillSignalled(); semaphore.waitTillSignalled();
} }
} }
void ReadWriteMutex::UnLockWrite() { void ReadWriteMutex::UnLockWrite() {
uint32 totalLocks = maxReaders(); uint32 totalLocks = maxReaders();
for (int i = 0; i < totalLocks; ++i) { for(unsigned int i = 0; i < totalLocks; ++i) {
semaphore.signal(); semaphore.signal();
} }
} }