Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure joy_connection_changed is emitted on the main thread #80432

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S
}
joy_names[p_idx] = js;

emit_signal(SNAME("joy_connection_changed"), p_idx, p_connected);
// Ensure this signal is emitted on the main thread, as some platforms (e.g. Linux) call this from a different thread.
call_deferred("emit_signal", SNAME("joy_connection_changed"), p_idx, p_connected);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a comment to clarify, like "Defer to emit on the main thread." (IIUC).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I'm not good with multithreading, but would deferring the call to joy_connection_changed in the Linux input code solve the issue similarly?

If only some platforms do this in a thread, maybe they should be responsible for deferring to the main thread where needed?

Though this one claims to be thread-safe so I guess this helps provide this guarantee?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, from what I've checked it seems only Linux runs on a thread, and I did try making this change there initially. But for some reason, it didn't work: on Godot 4, the signal stopped being emitted altogether; on Godot 3, the signal stopped being emitted when a joypad is disconnected, and every time I reconnected the joypad it registered a new device index.

}

Vector3 Input::get_gravity() const {
Expand Down