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
This commit is contained in:
George McMullen 2019-10-15 04:13:06 -07:00 committed by Vas Crabb
parent 6daeb4b4d1
commit 4a2d4b3911

View File

@ -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);