From 771d0a1c7d00e535ab94a8009475e232846422eb Mon Sep 17 00:00:00 2001 From: din Date: Mon, 14 Sep 2020 23:10:59 -0400 Subject: [PATCH] check pacdrive functions before calling them Before, if the PacDrive32.dll provided by Ultimarc wasn't found, stepmania would attempt to write to the Pac-Drive anyway, resulting in a call on a null pointer. This adds a quick check against PacDriveConnected during the update, and checks if the pacdrive functions exist before calling them. --- src/arch/Lights/LightsDriver_PacDrive.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/arch/Lights/LightsDriver_PacDrive.cpp b/src/arch/Lights/LightsDriver_PacDrive.cpp index 862cc12296..139c1326ed 100644 --- a/src/arch/Lights/LightsDriver_PacDrive.cpp +++ b/src/arch/Lights/LightsDriver_PacDrive.cpp @@ -39,7 +39,10 @@ LightsDriver_PacDrive::LightsDriver_PacDrive() m_pacset = (PacSetLEDStates*)GetProcAddress(PachDLL, "PacSetLEDStates"); m_pacdone = (PacShutdown*)GetProcAddress(PachDLL, "PacShutdown"); - int NumPacDrives = m_pacinit(); //initialize the pac drive + int NumPacDrives = 0; + + if (m_pacinit) + NumPacDrives = m_pacinit(); //initialize the pac drive if (NumPacDrives == 0) { @@ -60,9 +63,12 @@ LightsDriver_PacDrive::LightsDriver_PacDrive() LightsDriver_PacDrive::~LightsDriver_PacDrive() { - if (PacDriveConnected) + if (PacDriveConnected && m_pacset) m_pacset(0, 0x0); // clear all lights for device i - m_pacdone(); + + if (m_pacdone) + m_pacdone(); + FreeLibrary(PachDLL); } @@ -110,7 +116,10 @@ void LightsDriver_PacDrive::Set(const LightsState *ls) if (ls->m_bGameButtonLights[GameController_2][GAME_BUTTON_START]) outb |= BIT(14); break; } - m_pacset(0, outb); + + //ensure m_pacset function call was loaded. + if (m_pacset) + m_pacset(0, outb); } /* Modified 2015 Dave Barribeau for StepMania 5.09