- fixing crash on client connect screen

This commit is contained in:
Mark Vejvoda 2010-08-05 00:48:46 +00:00
parent ac31d06106
commit 1a2f0175a8
4 changed files with 40 additions and 17 deletions

View File

@ -24,10 +24,18 @@
namespace Glest{ namespace Game{ namespace Glest{ namespace Game{
//misc consts //misc consts
struct MapInfo{ class MapInfo {
public:
Vec2i size; Vec2i size;
int players; int players;
string desc; string desc;
MapInfo() {
size = Vec2i(0,0);
players = 0;
desc = "";
}
}; };
struct ScenarioInfo struct ScenarioInfo

View File

@ -50,11 +50,6 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
{ {
lastNetworkSendPing = 0; lastNetworkSendPing = 0;
pingCount = 0; pingCount = 0;
returnMenuInfo=joinMenuInfo;
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
Config &config = Config::getInstance();
needToSetChangedGameSettings = false; needToSetChangedGameSettings = false;
lastSetChangedGameSettings = time(NULL); lastSetChangedGameSettings = time(NULL);
showFullConsole=false; showFullConsole=false;
@ -62,7 +57,14 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
currentFactionName=""; currentFactionName="";
currentMap=""; currentMap="";
settingsReceivedFromServer=false; settingsReceivedFromServer=false;
initialSettingsReceivedFromServer=false;
returnMenuInfo=joinMenuInfo;
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
Config &config = Config::getInstance();
labelMapInfo.setText("?");
vector<string> teamItems, controlItems, results; vector<string> teamItems, controlItems, results;
//state //state
@ -225,7 +227,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
labelFaction.setText(lang.get("Faction")); labelFaction.setText(lang.get("Faction"));
labelTeam.setText(lang.get("Team")); labelTeam.setText(lang.get("Team"));
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__);
labelMapInfo.setText(mapInfo.desc); labelMapInfo.setText(mapInfo.desc);
//init controllers //init controllers
@ -240,8 +242,6 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
NetworkManager &networkManager= NetworkManager::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance();
ClientInterface* clientInterface= networkManager.getClientInterface(); ClientInterface* clientInterface= networkManager.getClientInterface();
//if (!settingsReceivedFromServer) return;
if(buttonDisconnect.mouseClick(x,y)){ if(buttonDisconnect.mouseClick(x,y)){
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__);
@ -261,9 +261,13 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
currentFactionName=""; currentFactionName="";
currentMap=""; currentMap="";
returnToJoinMenu(); returnToJoinMenu();
return;
} }
if (!initialSettingsReceivedFromServer) return;
// Only allow changes after we get game settings from the server // Only allow changes after we get game settings from the server
else if( clientInterface->isConnected() == true && if( clientInterface->isConnected() == true &&
clientInterface->getGameSettingsReceived() == true) { clientInterface->getGameSettingsReceived() == true) {
if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) { if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
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__);
@ -358,7 +362,7 @@ void MenuStateConnectedGame::render(){
try { try {
//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__);
if (!settingsReceivedFromServer) return; if (!initialSettingsReceivedFromServer) return;
//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__);
@ -672,6 +676,7 @@ void MenuStateConnectedGame::update()
} }
settingsReceivedFromServer=true; settingsReceivedFromServer=true;
initialSettingsReceivedFromServer=true;
} }
} }
} }

View File

@ -86,6 +86,7 @@ private:
bool settingsReceivedFromServer; bool settingsReceivedFromServer;
time_t lastNetworkSendPing; time_t lastNetworkSendPing;
int pingCount; int pingCount;
bool initialSettingsReceivedFromServer;
public: public:

View File

@ -1,7 +1,7 @@
// ============================================================== // ==============================================================
// This file is part of Glest Shared Library (www.glest.org) // This file is part of Glest Shared Library (www.glest.org)
// //
// Copyright (C) 2001-2007 Martiño Figueroa // Copyright (C) 2001-2007 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
@ -10,11 +10,18 @@
// ============================================================== // ==============================================================
#include "font.h" #include "font.h"
#include <stdexcept>
#include "conversion.h"
#include "leak_dumper.h" #include "leak_dumper.h"
using namespace std;
using namespace Shared::Util;
namespace Shared{ namespace Graphics{ namespace Shared{ namespace Graphics{
int Font::charCount= 256;
std::string Font::fontTypeName = "Times New Roman";
// ===================================================== // =====================================================
// class FontMetrics // class FontMetrics
// ===================================================== // =====================================================
@ -30,11 +37,16 @@ FontMetrics::FontMetrics(){
FontMetrics::~FontMetrics(){ FontMetrics::~FontMetrics(){
delete [] widths; delete [] widths;
widths = NULL;
} }
float FontMetrics::getTextWidth(const string &str) const{ float FontMetrics::getTextWidth(const string &str) const{
float width= 0.f; float width= 0.f;
for(unsigned int i=0; i<str.size(); ++i){ for(unsigned int i=0; i< str.size() && i < Font::charCount; ++i){
if(str[i] >= Font::charCount) {
string sError = "str[i] >= Font::charCount, [" + str + "] i = " + intToStr(i);
throw runtime_error(sError);
}
width+= widths[str[i]]; width+= widths[str[i]];
} }
return width; return width;
@ -48,9 +60,6 @@ float FontMetrics::getHeight() const{
// class Font // class Font
// =============================================== // ===============================================
int Font::charCount= 256;
std::string Font::fontTypeName = "Times New Roman";
Font::Font(){ Font::Font(){
inited= false; inited= false;
type= fontTypeName; type= fontTypeName;