Change gamepad state logic to fix crash #445
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This change fixes #426 by moving the gamepad state change logic into the constructor, which ensures it will not be updated until the object is finished being constructed, and therefore not be attempted to be accessed until it is initialized.
Context
Sometime late last year, I started getting a bug where OBS would crash on boot if not in safe mode. My OBS and input-display were both up to date, OBS would run normally without input-display active (or in safe mode), and I had no other plugins installed, so I knew the issue must be with input-display. In addition, the issue persisted across platforms (Flatpak, as well as Portage; and it seems like the issue is also present on Windows, as the linked issue shows). I did some digging and found the above-linked issue, which had the exact same error, log, callstack/backtrace, and also a workaround (unplugging the controller before booting OBS).
When troubleshooting, this is the full backtrace I got with debugging symbols:
The problem lies in
#5
:What ends up happening is
local_gamepads::get_controller_from_index
is getting called on agamepad
that has not been initialized, which crashes because of something regarding the SDL2 init function that gets run.Fix
The issue can be fixed one of two ways:
gamepad
s so that the SDL init doesn't fail: