Close database when done

This prevents messages 'Connection reset by peer' in the postgresql log file.

It might have benefits for other databases as well ?
This commit is contained in:
Rogier 2016-05-23 12:46:25 +02:00
parent ba9166fd79
commit dbec678f6b
3 changed files with 12 additions and 0 deletions

View File

@ -202,6 +202,7 @@ TileGenerator::TileGenerator():
TileGenerator::~TileGenerator()
{
closeDb();
}
void TileGenerator::setSilenceSuggestion(unsigned flags)
@ -557,6 +558,7 @@ void TileGenerator::generate(const std::string &input, const std::string &output
if (!m_drawObjects.empty()) {
renderDrawObjects();
}
closeDb();
if (progressIndicator)
cout << "Writing image...\r" << std::flush;
writeImage(output);
@ -859,6 +861,14 @@ void TileGenerator::openDb(const std::string &input)
throw std::runtime_error(((std::string) "World uses backend '") + m_backend + ", which was not enabled at compile-time.");
}
void TileGenerator::closeDb()
{
if (m_db) {
delete m_db;
m_db = NULL;
}
}
void TileGenerator::loadBlocks()
{
int mapXMin, mapXMax;

View File

@ -162,6 +162,7 @@ private:
std::string getWorldDatabaseBackend(const std::string &input);
int getMapChunkSize(const std::string &input);
void openDb(const std::string &input);
void closeDb();
void sanitizeParameters(void);
void loadBlocks();
void createImage();

1
db.h
View File

@ -12,6 +12,7 @@
class DB {
public:
virtual ~DB() {}
typedef std::pair<BlockPos, ustring> Block;
typedef std::vector<BlockPos> BlockPosList;
virtual const BlockPosList &getBlockPosList()=0;