Friday, September 11, 2020

Ghost Windows & PS4 Controller Input

Gateware is going through its last round of bug fixes before version 1.2a is released. The hope was to have the release ready at the start of this past week, but a few new bugs and several failed manual tests set us back a bit. These issues have the potential to cause grief to any developer that uses Gateware. Having them fixed will ensure developers have a consistent, hassle-free experience with Gateware.

New bugs

During all this testing, I found several new issues:

  • On Mac, GWindow tests sometimes cause a closed window's outline to remain on the screen. 
  • On Mac, GController does not detect the down button of a PS4 controller. 
  • On Linux, GController doesn't respond to Xbox controller connection events. 
  • On Windows, GInput tests do not pass the scroll-wheel checks. 

It wasn't immediately clear to me how to fix these problems. Other minor issues came up during the tests, but they were straightforward enough to fix on the spot.


Ghost windows

The shadow left behind by a closed window looks ghost-like to me. It would also stick around or "haunt" the desktop until all Unit Tests had finished.


I found the Create() and Reconfigure() Unit Test I made last week was the only place the problem occurred. I narrowed it down further to it happening only when the window is reconfigured to or from fullscreen. I'm not certain what the root cause of the issue is. However, if the Unit Tests are slowed down, thereby creating more time between window transitions, each window closes without leaving behind a shadowy remnant. Slowing down the code causing the transition to and from fullscreen fixed half of the problem. Waiting for the window to finish resizing before styling it, fixed the other half. I'm not satisfied with the solution as it is difficult to follow. There must be a better way to handle window style changes on the Mac, but I haven't found it yet. For now, the current solution works.

Mouse move crashes

Just as I was running my last round of Unit Tests to verify my ghost window fix, I found another bug from something I worked on in the past. Towards the end of the Unit Tests, a window is created for GBufferedInput. If your mouse happens to move within that window while it is on screen, the program crashes with an EXC_BAD_ACCESS error. The error seemed similar to the EXC_BAD_ACCESS errors I was getting last week with GWindow. The error occurred when the window was deallocated before an overridden NSResponder function like windowWillClosed() had been called. In this case, the window was being deallocated before mouseMoved() had been called. Luckily, this was an easy fix; stop mouse events before closing the window.


PS4 directional-pad partially supported

I would not have noticed this bug if the Mac driver for my wired Xbox controller was still working. Thankfully, connecting the PS4 controller to Mac with Bluetooth is easy to do, requiring no additional driver downloads. I know the D-Pad on the Xbox controller is detected fine because I tested it with these Unit Tests a few weeks ago. After the PS4 controller failed the down button test, I modified the Unit Test to check the other directional buttons. I discovered the up button was the only D-Pad button that was detected. GController_mac.hpp has a hefty amount of code checking the input of the controller. Thankfully, all the code I needed to modify was in a big switch statement laid out sensibly enough that I could make modifications easily. After outputting the raw controller D-Pad values, I added them to the directional code already in place. Afterward, the D-Pad passed its Unit Test.


More to go

Even though the D-Pad problem is fixed, there might be more issues with PS4 input. Updating the current controller Unit Test to test more controller input values would verify controller input is detected correctly. There is also the controller connection issue on Linux and the GInput scroll wheel detection on Windows that I haven't gotten to yet. After all that is done, Gateware users will finally get access to version 1.2a and all its glory.

No comments:

Post a Comment