Properly fixed . Made a global variable part of the

KartSelection object, to avoid the two instances of the
kart selection screen to interfere with each other. Removed
tearing down the kart selection screen. Also fixed crash
when starting the kart screen after a network kart screen.
This commit is contained in:
hiker 2016-05-10 17:27:50 +10:00
parent 898cefc91e
commit 01ce2c32ef
6 changed files with 17 additions and 22 deletions

View File

@ -148,8 +148,6 @@ EventPropagation FocusDispatcher::focused(const int player_id)
return GUIEngine::EVENT_LET;
} // focused
static FocusDispatcher *g_dispatcher = NULL;
#if 0
#pragma mark -
#pragma mark KartHoverListener
@ -229,6 +227,7 @@ bool sameKart(const PlayerKartWidget& player1, const PlayerKartWidget& player2)
KartSelectionScreen::KartSelectionScreen(const char* filename) : Screen(filename)
{
m_dispatcher = NULL;
m_removed_widget = NULL;
m_multiplayer_message = NULL;
m_from_overworld = false;
@ -246,8 +245,8 @@ KartSelectionScreen* KartSelectionScreen::getRunningInstance()
void KartSelectionScreen::loadedFromFile()
{
g_dispatcher = new FocusDispatcher(this);
m_first_widget = g_dispatcher;
m_dispatcher = new FocusDispatcher(this);
m_first_widget = m_dispatcher;
m_game_master_confirmed = false;
m_multiplayer_message = NULL;
// Dynamically add tabs
@ -305,6 +304,7 @@ void KartSelectionScreen::beforeAddingWidget()
void KartSelectionScreen::init()
{
m_instance_ptr = this;
Screen::init();
m_must_delete_on_back = false;
@ -318,17 +318,17 @@ void KartSelectionScreen::init()
// FIXME : The reserved id value is -1 when we switch from KSS to NKSS and vice-versa
g_dispatcher->setRootID(placeholder->m_reserved_id);
m_dispatcher->setRootID(placeholder->m_reserved_id);
g_root_id = placeholder->m_reserved_id;
if (!m_widgets.contains(g_dispatcher))
if (!m_widgets.contains(m_dispatcher))
{
m_widgets.push_back(g_dispatcher);
m_widgets.push_back(m_dispatcher);
// this is only needed if the dispatcher wasn't already in
// the list of widgets. If it already was, it was added along
// other widgets.
g_dispatcher->add();
m_dispatcher->add();
}
m_game_master_confirmed = false;
@ -426,7 +426,7 @@ void KartSelectionScreen::tearDown()
void KartSelectionScreen::unloaded()
{
// these pointer is no more valid (have been deleted along other widgets)
g_dispatcher = NULL;
m_dispatcher = NULL;
}
// ----------------------------------------------------------------------------
@ -439,7 +439,7 @@ bool KartSelectionScreen::joinPlayer(InputDevice* device)
Log::info("KartSelectionScreen", "joinPlayer() invoked");
if (!m_multiplayer && !first_player) return false;
assert (g_dispatcher != NULL);
assert (m_dispatcher != NULL);
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
if (w == NULL)

View File

@ -36,6 +36,7 @@ namespace Online
class OnlineProfile;
}
class FocusDispatcher;
class InputDevice;
class KartHoverListener;
@ -79,6 +80,8 @@ protected:
/** Message shown in multiplayer mode */
GUIEngine::BubbleWidget* m_multiplayer_message;
FocusDispatcher *m_dispatcher;
KartSelectionScreen(const char* filename);
/** Called when all players selected their kart */

View File

@ -37,6 +37,7 @@
#include "modes/cutscene_world.hpp"
#include "modes/overworld.hpp"
#include "modes/demo_world.hpp"
#include "network/network_config.hpp"
#include "online/request_manager.hpp"
#include "states_screens/addons_screen.hpp"
#include "states_screens/credits.hpp"
@ -385,7 +386,8 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
#endif
if (selection == "new")
{
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance(); //FIXME : that was for tests
NetworkConfig::get()->unsetNetworking();
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance();
s->setMultiplayer(false);
s->setFromOverworld(false);
s->push();
@ -393,6 +395,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
else if (selection == "multiplayer")
{
KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance();
NetworkConfig::get()->unsetNetworking();
s->setMultiplayer(true);
s->setFromOverworld(false);
s->push();

View File

@ -44,7 +44,6 @@ DEFINE_SCREEN_SINGLETON( NetworkKartSelectionScreen );
NetworkKartSelectionScreen::NetworkKartSelectionScreen()
: KartSelectionScreen("karts_online.stkgui")
{
KartSelectionScreen::m_instance_ptr = this;
} // NetworkKartSelectionScreen
// ----------------------------------------------------------------------------

View File

@ -21,7 +21,6 @@ DEFINE_SCREEN_SINGLETON( OfflineKartSelectionScreen );
OfflineKartSelectionScreen::OfflineKartSelectionScreen() : KartSelectionScreen("karts.stkgui")
{
KartSelectionScreen::m_instance_ptr = this;
}
OfflineKartSelectionScreen::~OfflineKartSelectionScreen()

View File

@ -386,10 +386,6 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
{
race_manager->exitRace();
race_manager->setAIKartOverride("");
// FIXME: why is this call necessary here? tearDown should be
// automatically called when the screen is left. Note that the
// NetworkKartSelectionScreen::getInstance()->tearDown(); caused #1347
KartSelectionScreen::getRunningInstance()->tearDown();
Screen* newStack[] = { MainMenuScreen::getInstance(),
RaceSetupScreen::getInstance(),
NULL };
@ -403,11 +399,6 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget,
{
race_manager->exitRace();
race_manager->setAIKartOverride("");
// FIXME: why is this call necessary here? tearDown should be
// automatically called when the screen is left. Note that the
// NetworkKartSelectionScreen::getInstance()->tearDown(); caused #1347
//if (KartSelectionScreen::getRunningInstance() != NULL)
// KartSelectionScreen::getRunningInstance()->tearDown();
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
if (race_manager->raceWasStartedFromOverworld())