Skip to content

joystickstatuswindow: don't update accel/gyro if closed - #1229

Merged
pktiuk merged 1 commit into
AntiMicroX:masterfrom
xobs:fix-segfault-on-controller-properties-closed
Sep 3, 2025
Merged

joystickstatuswindow: don't update accel/gyro if closed#1229
pktiuk merged 1 commit into
AntiMicroX:masterfrom
xobs:fix-segfault-on-controller-properties-closed

Conversation

@xobs

@xobs xobs commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

Avoid updating the accelerometer or gyroscope values if the window is closed. This prevents a segfault when the window is closed for controllers with accelerometers and gyroscopes, such as DualSense controllers.

@xobs

xobs commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

Currently, this only fixes the issue if the QDialog is closed by pressing "Esc". It does not fix it when closing by clicking the close box in the upper-right corner of the window.

@xobs

xobs commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

This was an attempt to fix #1230 but it does not fix the case where the close box is clicked.

@xobs

xobs commented Sep 1, 2025

Copy link
Copy Markdown
Contributor Author

I wish Qt would not repaint an object if it didn't exist, but I can't seem to find a way of testing whether an object exists prior to calling setValue(). The problem appears to be that the window decoration is deallocated sometime during the call to setValue(), and then Qt continues to perform the paint operation.

@pktiuk

pktiuk commented Sep 1, 2025

Copy link
Copy Markdown
Member

Hello @xobs ,

Could you fix formatting in this PR?

@xobs
xobs force-pushed the fix-segfault-on-controller-properties-closed branch 2 times, most recently from cf993d3 to a18ce17 Compare September 2, 2025 02:35
@xobs

xobs commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Of course. It didn't sit right with me that the fix was only partially successful, so I wanted to come up with a more complete fix. This should now work for both the case where the user clicks the close box on the window decoration, as well as the user clicking the "Close" button. It should also still work for devices with no sensors.

The difference was to delete the whole QDialog box (which will cause it to close), but defer the deletion until the end of the runloop. That way the gyro and accel labels can still be updated, even if the window is closed while the values are getting updated.

I have only tested it under Wayland.

Comment thread src/gui/joystickstatuswindow.cpp
Defer deleting the window when it's closed until after the main loop has
run. This prevents a segfault when the window is closed for
controllers with accelerometers and gyroscopes, such as DualSense
controllers.

Signed-off-by: Sean Cross <sean@xobs.io>
@xobs
xobs force-pushed the fix-segfault-on-controller-properties-closed branch from a18ce17 to f8388ec Compare September 3, 2025 02:08
@pktiuk
pktiuk merged commit 805a323 into AntiMicroX:master Sep 3, 2025
9 checks passed
@pktiuk

pktiuk commented Sep 3, 2025

Copy link
Copy Markdown
Member

Thank you for your contribution. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants