summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd
diff options
context:
space:
mode:
authorGravatarGravatar George McMullen <spam-g-github@kreation.com>2019-10-15 04:13:06 -0700
committerGravatarGravatar Vas Crabb <cuavas@users.noreply.github.com>2019-10-15 22:13:06 +1100
commit4a2d4b3911488fc73d3443ec569093860e37be38 (patch)
treed676ddc317566baa2baf3ecba715aea8128a2fa5 /src/osd
parent6daeb4b4d14ca313be5b386ca61b6c4222d2e002 (diff)
Check that m_display is not null to prevent crash (#5725)
* Check that m_display is not null to prevent crash https://mametesters.org/view.php?id=7372 * Probe method to check if X11 is actually being used As per: https://github.com/mamedev/mame/pull/5725#issuecomment-540004475 this will help MAME verify X11 has no inputs when X11 is not actually being used (e.g. on RetroPie where SDL display is RPI). * Fix issue where a lightgun with no name would return nullptr As suggested by https://github.com/mamedev/mame/pull/5725#issuecomment-539914514 , a bug in create_lightgun_device() returned nullptr if the lightgun had no name. Now it will create the device with a name using the lightgun's device index * Change older m_display change to assert This module can now be probed and disabled correctly if X11 is not being used. Removed the if statements that would be called every cycle (and fail silently) in favor of asserts, as MAME does not currently handle dynamic hardware configuration changes. * Fixing semicolons in asserts that were ifs
Diffstat (limited to 'src/osd')
-rw-r--r--src/osd/modules/input/input_x11.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/osd/modules/input/input_x11.cpp b/src/osd/modules/input/input_x11.cpp
index 07ade15c764..6b66220e32a 100644
--- a/src/osd/modules/input/input_x11.cpp
+++ b/src/osd/modules/input/input_x11.cpp
@@ -312,6 +312,9 @@ public:
std::lock_guard<std::mutex> scope_lock(m_lock);
XEvent xevent;
+ // If X11 has become invalid for some reason, XPending will crash. Assert instead.
+ assert(m_display != nullptr);
+
//Get XInput events
while (XPending(m_display) != 0)
{
@@ -443,6 +446,17 @@ public:
{
}
+ virtual bool probe() override
+ {
+ // If there is no X server, X11 lightguns cannot be supported
+ if (XOpenDisplay(nullptr) == nullptr)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
void input_init(running_machine &machine) override
{
int index;
@@ -454,6 +468,9 @@ public:
x11_event_manager::instance().initialize();
m_display = x11_event_manager::instance().display();
+ // If the X server has become invalid, a crash can occur
+ assert(m_display != nullptr);
+
// Loop through all 8 possible devices
for (index = 0; index < 8; index++)
{
@@ -573,10 +590,9 @@ private:
if (m_lightgun_map.initialized)
{
snprintf(tempname, ARRAY_LENGTH(tempname), "NC%d", index);
- devicelist()->create_device<x11_lightgun_device>(machine, tempname, tempname, *this);
- }
-
- return nullptr;
+ return devicelist()->create_device<x11_lightgun_device>(machine, tempname, tempname, *this);
+ } else
+ return nullptr;
}
return devicelist()->create_device<x11_lightgun_device>(machine, m_lightgun_map.map[index].name.c_str(), m_lightgun_map.map[index].name.c_str(), *this);