Skip to content

Conversation

hwsmm
Copy link
Contributor

@hwsmm hwsmm commented Jan 21, 2025

As explained in the discussion, it may be the case that all monitors are turned off and the window is left alone without any displays. Current osu!framework implementation expects there to be at least one display, and such expectation makes the game crash when there is no display available.

To fix the issue, this PR makes Display nullable in IWindow, and adds some checks to make it less unsafe. However, there still needs to be one display on launch. This PR only lets Display nullable later on.

I understand that making Display nullable sounds not so good, but I think it's less surprising than letting the game crash on a sudden monitor disconnection. I made a contact to the issue reporter, and confirmed that this PR fixes the issue.

Feel free to reject this PR if it doesn't feel right for you.

It's hard to add the test case since it doesn't seem to happen on Windows, and it would require manual intervention (turning off the monitor)... I'd like to hear if there is any idea for this.

@hwsmm
Copy link
Contributor Author

hwsmm commented Jan 21, 2025

Will fix tests soon...

@Susko3
Copy link
Member

Susko3 commented Jan 21, 2025

If you want to make it not crash, just ensure that the display is never set to null – in case there is no display, just lie to everyone that the last display is still current. Nullable display will complicated game code for no reason.

@hwsmm
Copy link
Contributor Author

hwsmm commented Jan 21, 2025

I did what you suggested before trying this option, but it ended up with bunch of invalid display errors, so I decided to stop all operations regarding to Display until it becomes available again.

Copy link
Member

@Susko3 Susko3 left a comment

Choose a reason for hiding this comment

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

I actually don't hate this diff, it does make sense to allow null display.

@peppy peppy self-requested a review January 21, 2025 05:28
Copy link
Member

@peppy peppy left a comment

Choose a reason for hiding this comment

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

dunno


default:
windowLocation = Host.Window.CurrentDisplayBindable.Value.Bounds.Location;
windowLocation = Host.Window.CurrentDisplayBindable.Value?.Bounds.Location ?? Host.Window.Position;
Copy link
Member

Choose a reason for hiding this comment

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

This breaks my mind. Does this fallback really work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be fine as a fallback according to #6440. It seems to work fine on Linux, too.

event Action<IEnumerable<Display>>? DisplaysChanged;

/// <summary>
/// Gets the <see cref="Display"/> that has been set as "primary" or "default" in the operating system.
Copy link
Member

Choose a reason for hiding this comment

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

Needs to explain how/when it can be null.

@hwsmm
Copy link
Contributor Author

hwsmm commented Jan 21, 2025

Along with peppy's comment, I'll revisit after I understand a bit more how SDL or X11/Wayland is dealing with display disconnection. Considering that this only happens on Linux (so far), this needs more consideration.

@hwsmm hwsmm marked this pull request as draft January 21, 2025 05:36
@pull-request-size pull-request-size bot added size/L and removed size/M labels Feb 26, 2025
@hwsmm
Copy link
Contributor Author

hwsmm commented Feb 26, 2025

Having no display seems to be an undefined behavior in SDL (obviously). I can probably submit some patches to SDL, but this isn't something to fix because... I think an user needs to fix their monitor first. We just need to handle it more gracefully than crashing out.

Either Windows or my GPU driver probably doesn't report no display as I couldn't find code in SDL that keeps at least one display alive, so it doesn't happen on Windows but only happens on Linux. Anyway, it can happen with simple monitor disconnection/sleep and wakeup on Linux, so I think it's better to be as defensive as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants