Bugfix for tracker#: 2985601

- Added checking for NULL pointer as well as clients now check connection state of the server during load.
This commit is contained in:
Mark Vejvoda
2010-04-12 20:32:47 +00:00
parent f7df0fd3d4
commit 4e12d8dbcf
6 changed files with 141 additions and 77 deletions

View File

@@ -190,7 +190,7 @@ void Game::load(){
} }
} }
//throw runtime_error("Test!");
//tileset //tileset
world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum); world.loadTileset(config.getPathListForType(ptTilesets,scenarioDir), tilesetName, &checksum);

View File

@@ -1,4 +1,3 @@
// ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Martio Figueroa // Copyright (C) 2001-2008 Martio Figueroa
@@ -58,9 +57,10 @@ public:
} }
static void handleRuntimeError(const char *msg) { static void handleRuntimeError(const char *msg) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,msg);
Program *program = Program::getInstance(); Program *program = Program::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%s] gameInitialized = %d, program = %p\n",__FILE__,__FUNCTION__,__LINE__,msg,gameInitialized,program);
if(program && gameInitialized == true) { if(program && gameInitialized == true) {
//SystemFlags::Close(); //SystemFlags::Close();
program->showMessage(msg); program->showMessage(msg);
@@ -68,6 +68,7 @@ public:
else { else {
message("#2 An error ocurred and Glest will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file."); message("#2 An error ocurred and Glest will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file.");
} }
showCursor(true);
restoreVideoMode(true); restoreVideoMode(true);
//SystemFlags::Close(); //SystemFlags::Close();
exit(0); exit(0);
@@ -85,6 +86,7 @@ public:
} }
if(exitApp == true) { if(exitApp == true) {
showCursor(true);
restoreVideoMode(true); restoreVideoMode(true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg); SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n",msg);
//SystemFlags::Close(); //SystemFlags::Close();
@@ -306,12 +308,13 @@ 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__);
gameInitialized = true;
// test // test
//Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0); //Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0);
//throw runtime_error("test!"); //throw runtime_error("test!");
//ExceptionHandler::DisplayMessage("test!", false); //ExceptionHandler::DisplayMessage("test!", false);
gameInitialized = true;
//main loop //main loop
while(Window::handleEvent()){ while(Window::handleEvent()){
program->loop(); program->loop();

View File

@@ -81,7 +81,8 @@ void Program::ShowMessageProgramState::render() {
void Program::ShowMessageProgramState::mouseDownLeft(int x, int y) { void Program::ShowMessageProgramState::mouseDownLeft(int x, int y) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(msgBox.mouseClick(x,y)) { int button= 1;
if(msgBox.mouseClick(x,y,button)) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
program->exit(); program->exit();
@@ -235,29 +236,36 @@ void Program::resize(SizeState sizeState){
void Program::setState(ProgramState *programState, bool cleanupOldState) void Program::setState(ProgramState *programState, bool cleanupOldState)
{ {
try {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); if(cleanupOldState == true) {
delete this->programState;
}
if(cleanupOldState == true) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
delete this->programState;
this->programState= programState;
programState->load();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
programState->init();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
updateTimer.reset();
updateCameraTimer.reset();
fpsTimer.reset();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
}
catch(const exception &e){
//exceptionMessage(e);
//throw runtime_error(e.what());
this->showMessage(e.what());
setState(new Intro(this));
} }
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
this->programState= programState;
programState->load();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
programState->init();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] %d\n",__FILE__,__FUNCTION__,__LINE__);
updateTimer.reset();
updateCameraTimer.reset();
fpsTimer.reset();
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
} }
void Program::exit() { void Program::exit() {
@@ -425,7 +433,8 @@ void Program::showMessage(const char *msg) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
showCursor(Config::getInstance().getBool("Windowed")); //showCursor(Config::getInstance().getBool("Windowed"));
showCursor(false);
//MainWindow *mainWindow= new MainWindow(this); //MainWindow *mainWindow= new MainWindow(this);
init(this->window,false); init(this->window,false);

View File

@@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest (www.glest.org) // This file is part of Glest (www.glest.org)
// //
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa // Copyright (C) 2001-2008 Martio Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published

View File

@@ -422,7 +422,7 @@ void ClientInterface::updateKeyframe(int frameCount)
void ClientInterface::waitUntilReady(Checksum* checksum) void ClientInterface::waitUntilReady(Checksum* checksum)
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
Logger &logger= Logger::getInstance(); Logger &logger= Logger::getInstance();
@@ -436,16 +436,36 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
NetworkMessageReady networkMessageReady; NetworkMessageReady networkMessageReady;
sendMessage(&networkMessageReady); sendMessage(&networkMessageReady);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
int64 lastMillisCheck = 0; int64 lastMillisCheck = 0;
//wait until we get a ready message from the server //wait until we get a ready message from the server
while(true) while(true)
{ {
NetworkMessageType networkMessageType = getNextMessageType(true); if(isConnected() == false) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
string sErr = "Error, Server has disconnected!";
sendTextMessage(sErr,-1);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
DisplayErrorMessage(sErr);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
quit= true;
close();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
return;
}
NetworkMessageType networkMessageType = getNextMessageType(true);
if(networkMessageType == nmtReady) if(networkMessageType == nmtReady)
{ {
if(receiveMessage(&networkMessageReady)) if(receiveMessage(&networkMessageReady))
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
break; break;
} }
} }
@@ -453,12 +473,21 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
{ {
if(chrono.getMillis() > readyWaitTimeout) if(chrono.getMillis() > readyWaitTimeout)
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
//throw runtime_error("Timeout waiting for server"); //throw runtime_error("Timeout waiting for server");
string sErr = "Timeout waiting for server"; string sErr = "Timeout waiting for server";
sendTextMessage(sErr,-1); sendTextMessage(sErr,-1);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
DisplayErrorMessage(sErr); DisplayErrorMessage(sErr);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
quit= true; quit= true;
close(); close();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
return; return;
} }
else else
@@ -475,11 +504,20 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
} }
else else
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
//throw runtime_error(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType) ); //throw runtime_error(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType) );
sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1); sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
DisplayErrorMessage(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType)); DisplayErrorMessage(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType));
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
quit= true; quit= true;
close(); close();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
return; return;
} }
@@ -487,19 +525,31 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
sleep(waitSleepTime); sleep(waitSleepTime);
} }
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
//check checksum //check checksum
if(networkMessageReady.getChecksum() != checksum->getSum()) if(networkMessageReady.getChecksum() != checksum->getSum())
//if(1)
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
string sErr = "Checksum error, you don't have the same data as the server"; string sErr = "Checksum error, you don't have the same data as the server";
//throw runtime_error("Checksum error, you don't have the same data as the server"); //throw runtime_error("Checksum error, you don't have the same data as the server");
sendTextMessage(sErr,-1); sendTextMessage(sErr,-1);
if(Config::getInstance().getBool("NetworkConsistencyChecks"))
{// error message and disconnect only if checked SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
DisplayErrorMessage(sErr);
quit= true; if(Config::getInstance().getBool("NetworkConsistencyChecks")) {
close(); // error message and disconnect only if checked
} SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
DisplayErrorMessage(sErr);
quit= true;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
close();
}
return; return;
} }

View File

@@ -37,67 +37,69 @@ namespace Glest{ namespace Game{
bool NetworkMessage::peek(Socket* socket, void* data, int dataSize) bool NetworkMessage::peek(Socket* socket, void* data, int dataSize)
{ {
int ipeekdatalen = socket->getDataToRead(); if(socket != NULL) {
int ipeekdatalen = socket->getDataToRead();
if(ipeekdatalen >= dataSize) if(ipeekdatalen >= dataSize)
{
if(socket->peek(data, dataSize)!=dataSize)
{ {
if(socket != NULL && socket->getSocketId() > 0) if(socket->peek(data, dataSize)!=dataSize)
{ {
throw runtime_error("Error peeking NetworkMessage"); if(socket != NULL && socket->getSocketId() > 0)
} {
else throw runtime_error("Error peeking NetworkMessage");
{ }
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__); else
} {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__);
}
}
else
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize);
}
return true;
} }
else else
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
} }
return true;
}
else
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
} }
return false; return false;
} }
bool NetworkMessage::receive(Socket* socket, void* data, int dataSize) bool NetworkMessage::receive(Socket* socket, void* data, int dataSize)
{ {
int ipeekdatalen = socket->getDataToRead(); if(socket != NULL) {
int ipeekdatalen = socket->getDataToRead();
if(ipeekdatalen >= dataSize) if(ipeekdatalen >= dataSize)
{
if(socket->receive(data, dataSize)!=dataSize)
{ {
if(socket != NULL && socket->getSocketId() > 0) if(socket->receive(data, dataSize)!=dataSize)
{ {
throw runtime_error("Error receiving NetworkMessage"); if(socket != NULL && socket->getSocketId() > 0)
} {
else throw runtime_error("Error receiving NetworkMessage");
{ }
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__); else
} {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__);
}
}
else
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize);
}
return true;
} }
else else
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] dataSize = %d\n",__FILE__,__FUNCTION__,dataSize); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
} }
return true;
}
else
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket->getDataToRead() returned %d\n",__FILE__,__FUNCTION__,ipeekdatalen);
} }
return false; return false;
} }
void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const
{ {
if(socket->send(data, dataSize)!=dataSize) if(socket != NULL && socket->send(data, dataSize)!=dataSize)
{ {
if(socket != NULL && socket->getSocketId() > 0) if(socket != NULL && socket->getSocketId() > 0)
{ {
@@ -105,7 +107,7 @@ void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const
} }
else else
{ {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] socket has been disconnected\n",__FILE__,__FUNCTION__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__);
} }
} }
} }