mirror of
https://github.com/glest/glest-source.git
synced 2025-08-25 09:10:49 +02:00
* added missing #include "leak_dumper.h" to new cpp files
* fix for map names not being formatted (and replaced explicit loops to do the same to tileSet & techTree) * fix exploration state for fog-of-war off & multiplayer (note: also turns off for AI, diff. behaviour to before) * added fogOfWar to GameSettings and added to cutom game menu/menu_state_custom_game.cpp
This commit is contained in:
121
source/shared_lib/include/util/leak_dumper.h
Normal file
121
source/shared_lib/include/util/leak_dumper.h
Normal file
@@ -0,0 +1,121 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _LEAKDUMPER_H_
|
||||
#define _LEAKDUMPER_H_
|
||||
|
||||
#define SL_LEAK_DUMP
|
||||
//SL_LEAK_DUMP controls if leak dumping is enabled or not
|
||||
|
||||
#ifdef SL_LEAK_DUMP
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
|
||||
//including this header in any file of a project will cause all
|
||||
//leaks to be dumped into leak_dump.txt, but only allocations that
|
||||
//ocurred in a file where this header is included will have
|
||||
//file and line number
|
||||
|
||||
struct AllocInfo{
|
||||
int line;
|
||||
const char *file;
|
||||
size_t bytes;
|
||||
void *ptr;
|
||||
bool free;
|
||||
bool array;
|
||||
|
||||
AllocInfo();
|
||||
AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class AllocRegistry
|
||||
// =====================================================
|
||||
|
||||
class AllocRegistry{
|
||||
private:
|
||||
static const unsigned maxAllocs= 40000;
|
||||
|
||||
private:
|
||||
AllocRegistry();
|
||||
|
||||
private:
|
||||
AllocInfo allocs[maxAllocs]; //array to store allocation info
|
||||
int allocCount; //allocations
|
||||
size_t allocBytes; //bytes allocated
|
||||
int nonMonitoredCount;
|
||||
size_t nonMonitoredBytes;
|
||||
|
||||
public:
|
||||
~AllocRegistry();
|
||||
|
||||
static AllocRegistry &getInstance();
|
||||
|
||||
void allocate(AllocInfo info);
|
||||
void deallocate(void* ptr, bool array);
|
||||
void reset();
|
||||
void dump(const char *path);
|
||||
};
|
||||
|
||||
//if an allocation ocurrs in a file where "leaks_dumper.h" is not included
|
||||
//this operator new is called and file and line will be unknown
|
||||
inline void * operator new (size_t bytes){
|
||||
void *ptr= malloc(bytes);
|
||||
AllocRegistry::getInstance().allocate(AllocInfo(ptr, "unknown", 0, bytes, false));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void operator delete(void *ptr){
|
||||
AllocRegistry::getInstance().deallocate(ptr, false);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
inline void * operator new[](size_t bytes){
|
||||
void *ptr= malloc(bytes);
|
||||
AllocRegistry::getInstance().allocate(AllocInfo(ptr, "unknown", 0, bytes, true));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void operator delete [](void *ptr){
|
||||
AllocRegistry::getInstance().deallocate(ptr, true);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
//if an allocation ocurrs in a file where "leaks_dumper.h" is included
|
||||
//this operator new is called and file and line will be known
|
||||
inline void * operator new (size_t bytes, char* file, int line){
|
||||
void *ptr= malloc(bytes);
|
||||
AllocRegistry::getInstance().allocate(AllocInfo(ptr, file, line, bytes, false));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void operator delete(void *ptr, char* file, int line){
|
||||
AllocRegistry::getInstance().deallocate(ptr, false);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
inline void * operator new[](size_t bytes, char* file, int line){
|
||||
void *ptr= malloc(bytes);
|
||||
AllocRegistry::getInstance().allocate(AllocInfo(ptr, file, line, bytes, true));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void operator delete [](void *ptr, char* file, int line){
|
||||
AllocRegistry::getInstance().deallocate(ptr, true);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#define new new(__FILE__, __LINE__)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -14,6 +14,8 @@
|
||||
#include "pixmap.h"
|
||||
#include <stdexcept>
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using std::runtime_error;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
@@ -10,6 +10,7 @@
|
||||
// ==============================================================
|
||||
|
||||
#include "ImageReaders.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
|
@@ -18,6 +18,8 @@
|
||||
#include <jpeglib.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using std::runtime_error;
|
||||
using std::ios;
|
||||
|
||||
|
@@ -17,6 +17,8 @@
|
||||
#include <png.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using std::runtime_error;
|
||||
using std::ios;
|
||||
|
||||
|
@@ -15,6 +15,8 @@
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using std::runtime_error;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
@@ -146,6 +148,6 @@ Pixmap2D* TGAReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
|
||||
std::cout << " ";
|
||||
}*/
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
}} //end namespace
|
||||
|
@@ -18,13 +18,10 @@
|
||||
#include "util.h"
|
||||
#include "math_util.h"
|
||||
#include "random.h"
|
||||
#include "leak_dumper.h"
|
||||
#include "FileReader.h"
|
||||
|
||||
//Readers
|
||||
#include "ImageReaders.h"
|
||||
|
||||
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
using namespace std;
|
||||
|
@@ -13,22 +13,12 @@
|
||||
|
||||
#ifdef SL_LEAK_DUMP
|
||||
|
||||
AllocInfo::AllocInfo(){
|
||||
ptr= NULL;
|
||||
file= "";
|
||||
line= -1;
|
||||
bytes= -1;
|
||||
array= false;
|
||||
free= true;
|
||||
AllocInfo::AllocInfo()
|
||||
: ptr(0), file(""), line(-1), bytes(-1), array(false), free(false) {
|
||||
}
|
||||
|
||||
AllocInfo::AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array){
|
||||
this->ptr= ptr;
|
||||
this->file= file;
|
||||
this->line= line;
|
||||
this->bytes= bytes;
|
||||
this->array= array;
|
||||
free= false;
|
||||
AllocInfo::AllocInfo(void* ptr, const char* file, int line, size_t bytes, bool array)
|
||||
: ptr(ptr), file(file), line(line), bytes(bytes), array(array), free(false) {
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
@@ -53,12 +43,7 @@ AllocRegistry &AllocRegistry::getInstance(){
|
||||
|
||||
AllocRegistry::~AllocRegistry(){
|
||||
|
||||
string leakLog = "leak_dump.log";
|
||||
if(getGameReadWritePath() != "") {
|
||||
leakLog = getGameReadWritePath() + leakLog;
|
||||
}
|
||||
|
||||
dump(leakLog.c_str());
|
||||
dump("leak_dump.log");
|
||||
}
|
||||
|
||||
void AllocRegistry::allocate(AllocInfo info){
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#ifdef SL_PROFILE
|
||||
|
||||
#include <stdexcept>
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
Reference in New Issue
Block a user