From 3861f9cec383792e19828e39441362426d9b0548 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Mon, 24 Feb 2020 19:04:48 -0600 Subject: [PATCH] HW/WiimoteEmu: Fill IR data with 0xFF on failed bus read. --- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index a9d564d116a6..aae789db90b3 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -516,8 +516,15 @@ void Wiimote::SendDataReport() const u8 camera_data_offset = CameraLogic::REPORT_DATA_OFFSET + rpt_builder.GetIRDataFormatOffset(); - m_i2c_bus.BusRead(CameraLogic::I2C_ADDR, camera_data_offset, rpt_builder.GetIRDataSize(), - rpt_builder.GetIRDataPtr()); + u8* ir_data = rpt_builder.GetIRDataPtr(); + const u8 ir_size = rpt_builder.GetIRDataSize(); + + if (ir_size != m_i2c_bus.BusRead(CameraLogic::I2C_ADDR, camera_data_offset, ir_size, ir_data)) + { + // This happens when IR reporting is enabled but the camera hardware is disabled. + // It commonly occurs when changing IR sensitivity. + std::fill_n(ir_data, ir_size, 0xff); + } } // Extension port: