Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when closing standalone games #12166

Merged
merged 4 commits into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions xbmc/cores/RetroPlayer/RetroPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ bool CRetroPlayer::OpenFile(const CFileItem& file, const CPlayerOptions& options
{
m_audio.reset(new CRetroPlayerAudio(*m_processInfo));
m_video.reset(new CRetroPlayerVideo(m_renderManager, *m_processInfo));
if (m_gameClient->OpenFile(file, m_audio.get(), m_video.get()))
{

if (!file.GetPath().empty())
bSuccess = m_gameClient->OpenFile(file, m_audio.get(), m_video.get());
else
bSuccess = m_gameClient->OpenStandalone(m_audio.get(), m_video.get());

if (bSuccess)
CLog::Log(LOGDEBUG, "RetroPlayer: Using game client %s", m_gameClient->ID().c_str());
bSuccess = true;
}
else
CLog::Log(LOGERROR, "RetroPlayer: Failed to open file using %s", m_gameClient->ID().c_str());
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/games/addons/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(SOURCES GameClient.cpp
GameClientInGameSaves.cpp
GameClientInput.cpp
GameClientJoystick.cpp
GameClientKeyboard.cpp
GameClientMouse.cpp
GameClientProperties.cpp
Expand All @@ -10,7 +10,7 @@ set(SOURCES GameClient.cpp
set(HEADERS GameClient.h
GameClientCallbacks.h
GameClientInGameSaves.h
GameClientInput.h
GameClientJoystick.h
GameClientKeyboard.h
GameClientMouse.h
GameClientProperties.h
Expand Down
12 changes: 6 additions & 6 deletions xbmc/games/addons/GameClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "GameClient.h"
#include "GameClientCallbacks.h"
#include "GameClientInGameSaves.h"
#include "GameClientInput.h"
#include "GameClientJoystick.h"
#include "GameClientKeyboard.h"
#include "GameClientMouse.h"
#include "GameClientTranslator.h"
Expand Down Expand Up @@ -258,7 +258,7 @@ bool CGameClient::OpenFile(const CFileItem& file, IGameAudioCallback* audio, IGa

// Check if we should open in standalone mode
if (file.GetPath().empty())
return OpenStandalone(audio, video);
return false;

// Resolve special:// URLs
CURL translatedUrl(CSpecialProtocol::TranslatePath(file.GetPath()));
Expand Down Expand Up @@ -294,9 +294,6 @@ bool CGameClient::OpenFile(const CFileItem& file, IGameAudioCallback* audio, IGa
if (!InitializeGameplay(file.GetPath(), audio, video))
return false;

m_inGameSaves.reset(new CGameClientInGameSaves(this, &m_struct.toAddon));
m_inGameSaves->Load();

return true;
}

Expand Down Expand Up @@ -345,6 +342,9 @@ bool CGameClient::InitializeGameplay(const std::string& gamePath, IGameAudioCall
if (m_bSupportsMouse)
OpenMouse();

m_inGameSaves.reset(new CGameClientInGameSaves(this, &m_struct.toAddon));
m_inGameSaves->Load();

// Start playback
CreatePlayback();

Expand Down Expand Up @@ -749,7 +749,7 @@ bool CGameClient::OpenPort(unsigned int port)
//! @todo Choose controller
ControllerPtr& controller = controllers[0];

m_ports[port].reset(new CGameClientInput(this, port, controller, &m_struct.toAddon));
m_ports[port].reset(new CGameClientJoystick(this, port, controller, &m_struct.toAddon));

// If keyboard input is being captured by this add-on, force the port type to PERIPHERAL_JOYSTICK
PERIPHERALS::PeripheralType device = PERIPHERALS::PERIPHERAL_UNKNOWN;
Expand Down
6 changes: 3 additions & 3 deletions xbmc/games/addons/GameClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace GAME
{

class CGameClientInGameSaves;
class CGameClientInput;
class CGameClientJoystick;
class CGameClientKeyboard;
class CGameClientMouse;
class IGameAudioCallback;
Expand Down Expand Up @@ -78,6 +78,7 @@ class CGameClient : public ADDON::CAddonDll
bool Initialize(void);
void Unload();
bool OpenFile(const CFileItem& file, IGameAudioCallback* audio, IGameVideoCallback* video);
bool OpenStandalone(IGameAudioCallback* audio, IGameVideoCallback* video);
void Reset();
void CloseFile();
const std::string& GetGamePath() const { return m_gamePath; }
Expand Down Expand Up @@ -118,7 +119,6 @@ class CGameClient : public ADDON::CAddonDll

private:
// Private gameplay functions
bool OpenStandalone(IGameAudioCallback* audio, IGameVideoCallback* video);
bool InitializeGameplay(const std::string& gamePath, IGameAudioCallback* audio, IGameVideoCallback* video);
bool LoadGameInfo();
bool NormalizeAudio(IGameAudioCallback* audioCallback);
Expand Down Expand Up @@ -192,7 +192,7 @@ class CGameClient : public ADDON::CAddonDll
std::unique_ptr<CGameClientInGameSaves> m_inGameSaves;

// Input
std::map<int, std::unique_ptr<CGameClientInput>> m_ports;
std::map<int, std::unique_ptr<CGameClientJoystick>> m_ports;
std::unique_ptr<CGameClientKeyboard> m_keyboard;
std::unique_ptr<CGameClientMouse> m_mouse;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

#include "GameClientInput.h"
#include "GameClientJoystick.h"
#include "GameClient.h"
#include "games/controllers/Controller.h"
#include "input/joysticks/IInputReceiver.h"
Expand All @@ -30,7 +30,7 @@
using namespace KODI;
using namespace GAME;

CGameClientInput::CGameClientInput(CGameClient* gameClient, int port, const ControllerPtr& controller, const KodiToAddonFuncTable_Game *dllStruct) :
CGameClientJoystick::CGameClientJoystick(CGameClient* gameClient, int port, const ControllerPtr& controller, const KodiToAddonFuncTable_Game *dllStruct) :
m_gameClient(gameClient),
m_port(port),
m_controller(controller),
Expand All @@ -40,12 +40,12 @@ CGameClientInput::CGameClientInput(CGameClient* gameClient, int port, const Cont
assert(m_controller.get() != NULL);
}

std::string CGameClientInput::ControllerID(void) const
std::string CGameClientJoystick::ControllerID(void) const
{
return m_controller->ID();
}

bool CGameClientInput::HasFeature(const std::string& feature) const
bool CGameClientJoystick::HasFeature(const std::string& feature) const
{
try
{
Expand All @@ -59,12 +59,12 @@ bool CGameClientInput::HasFeature(const std::string& feature) const
return false;
}

bool CGameClientInput::AcceptsInput(void)
bool CGameClientJoystick::AcceptsInput(void)
{
return m_gameClient->AcceptsInput();
}

JOYSTICK::INPUT_TYPE CGameClientInput::GetInputType(const std::string& feature) const
JOYSTICK::INPUT_TYPE CGameClientJoystick::GetInputType(const std::string& feature) const
{
const std::vector<CControllerFeature>& features = m_controller->Layout().Features();

Expand All @@ -77,7 +77,7 @@ JOYSTICK::INPUT_TYPE CGameClientInput::GetInputType(const std::string& feature)
return JOYSTICK::INPUT_TYPE::UNKNOWN;
}

bool CGameClientInput::OnButtonPress(const std::string& feature, bool bPressed)
bool CGameClientJoystick::OnButtonPress(const std::string& feature, bool bPressed)
{
bool bHandled = false;

Expand All @@ -103,7 +103,7 @@ bool CGameClientInput::OnButtonPress(const std::string& feature, bool bPressed)
return bHandled;
}

bool CGameClientInput::OnButtonMotion(const std::string& feature, float magnitude)
bool CGameClientJoystick::OnButtonMotion(const std::string& feature, float magnitude)
{
bool bHandled = false;

Expand All @@ -129,7 +129,7 @@ bool CGameClientInput::OnButtonMotion(const std::string& feature, float magnitud
return bHandled;
}

bool CGameClientInput::OnAnalogStickMotion(const std::string& feature, float x, float y, unsigned int motionTimeMs /* = 0 */)
bool CGameClientJoystick::OnAnalogStickMotion(const std::string& feature, float x, float y, unsigned int motionTimeMs /* = 0 */)
{
bool bHandled = false;

Expand All @@ -156,7 +156,7 @@ bool CGameClientInput::OnAnalogStickMotion(const std::string& feature, float x,
return bHandled;
}

bool CGameClientInput::OnAccelerometerMotion(const std::string& feature, float x, float y, float z)
bool CGameClientJoystick::OnAccelerometerMotion(const std::string& feature, float x, float y, float z)
{
bool bHandled = false;

Expand Down Expand Up @@ -184,7 +184,7 @@ bool CGameClientInput::OnAccelerometerMotion(const std::string& feature, float x
return bHandled;
}

bool CGameClientInput::SetRumble(const std::string& feature, float magnitude)
bool CGameClientJoystick::SetRumble(const std::string& feature, float magnitude)
{
bool bHandled = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace GAME
*
* Listens to game controller events and forwards them to the games (as game_input_event).
*/
class CGameClientInput : public KODI::JOYSTICK::IInputHandler
class CGameClientJoystick : public KODI::JOYSTICK::IInputHandler
{
public:
/*!
Expand All @@ -44,7 +44,9 @@ namespace GAME
* \param controller The game controller which is used (for controller mapping).
* \param dllStruct The emulator or game to which the events are sent.
*/
CGameClientInput(CGameClient* addon, int port, const ControllerPtr& controller, const KodiToAddonFuncTable_Game* dllStruct);
CGameClientJoystick(CGameClient* addon, int port, const ControllerPtr& controller, const KodiToAddonFuncTable_Game* dllStruct);

virtual ~CGameClientJoystick() = default;

// Implementation of IInputHandler
virtual std::string ControllerID(void) const override;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/addons/GameClientKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace GAME
/*!
* \brief Destructor unregisters from keyboard events from CInputManager.
*/
~CGameClientKeyboard();
virtual ~CGameClientKeyboard();

// implementation of IKeyboardHandler
virtual bool OnKeyPress(const CKey& key) override;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/addons/GameClientMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace GAME
/*!
* \brief Destructor unregisters from mouse events from CInputManager.
*/
~CGameClientMouse();
virtual ~CGameClientMouse();

// implementation of IMouseInputHandler
virtual std::string ControllerID(void) const override;
Expand Down
2 changes: 2 additions & 0 deletions xbmc/games/ports/PortManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace GAME
public:
static CPortManager& GetInstance();

virtual ~CPortManager() = default;

/*!
* \brief Request a new port be opened with input on that port sent to the
* specified handler.
Expand Down
2 changes: 1 addition & 1 deletion xbmc/games/tags/GameInfoTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace GAME
CGameInfoTag() { Reset(); }
CGameInfoTag(const CGameInfoTag& tag) { *this = tag; }
CGameInfoTag& operator=(const CGameInfoTag& tag);
~CGameInfoTag() { }
virtual ~CGameInfoTag() = default;
void Reset();

bool operator==(const CGameInfoTag& tag) const;
Expand Down
2 changes: 2 additions & 0 deletions xbmc/games/windows/GUIViewStateWindowGames.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace GAME
public:
CGUIViewStateWindowGames(const CFileItemList& items);

virtual ~CGUIViewStateWindowGames() = default;

// implementation of CGUIViewState
virtual std::string GetLockType() override;
virtual std::string GetExtensions() override;
Expand Down