window created twice

Found a bug in R'n'D? Report it here!

Moderators: Flumminator, Zomis

Post Reply
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

window created twice

Post by filbo »

This happens to me approximately 100% of the time that I start RnD...

I start the game, then immediately drag its window to where I want it.

Moments later, the game closes that window and opens a new one -- at the previous location. I drag it again.

Can you please either:

- don't close and reopen the window
- or, notice if the first window has been dragged; open the new window in the dropped location

?

(First one is better because there's nothing sensible you can do if the window re-creation happens in mid-drag...)

Linux, SDL2, I don't think any details are needed...
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: window created twice

Post by Holger »

Does this always happen, or only if you start R'n'D with a last played level set that has custom window dimensions?

I have tested this and was only able to reproduce this in the above mentioned latter case, like when starting R'n'D with one of the level sets from the EMC collection (which use a different windows size). What happens in this case is that R'n'D finds out that the last played level set has different window dimensions, and therefore reopens the window with these changed dimensions.

This also happens whenever you select another level set with window dimensions that differ from the current dimensions.

When implementing support for different window dimensions, I have though about these issues, but so far did not come up with a better solution. (Just resizing the window at its current position would be another solution, which has its own potentially nasty side effects.)
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: window created twice

Post by filbo »

It happens 100% of the time when starting the same levelset over and over. It's an EMC levelset (emc_haunted_mine_3), and I have half-size graphics turned on.

If that isn't sufficient to reproduce it, I can send you my setup.conf...
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: window created twice

Post by Holger »

OK, then it's perfectly clear: The game starts with default window size, finds out that it has to use a different window size, and re-creates the window with that different size. So this indeed happens every time you start the game.

If this is a "bug or feature" (when compared to resizing the existing windows instead of re-creating it) probably depends on what you're doing: If you like to have the game window centered on the screen, the current behaviour is probably what you want. If you like to have the game window in the lower right corner, both resizing and re-creating are probably not what you want.

Maybe I should really add a "-g" (geometry) style command line option, so the game could use (and keep) a specified x/y position in such cases... :-)

Or maybe you have a better idea to handle this problem?
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: window created twice

Post by filbo »

For my purposes -- all I want is that if I had dragged the window to a different place, it stays there. When you tear down the 1st and open the 2nd window, can you read out its location beforehand? Either by reading it immediately before, or by having a 'window being dragged' handler? I don't know what facilities are available in SDL...
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: window created twice

Post by filbo »

If the window's going to be a different size, I guess there is a question of what 'same place' means. Same upper left corner, or same center, I guess; and upper left makes more sense to me.
BryanFRitt
Posts: 219
Joined: Mon Nov 13, 2017 4:16 pm

Re: window created twice

Post by BryanFRitt »

filbo wrote: Wed Oct 13, 2021 10:22 pm If the window's going to be a different size, I guess there is a question of what 'same place' means. Same upper left corner, or same center, I guess; and upper left makes more sense to me.
One other thing that could be done for this is to make sure the new window is on screen as much as possible. Assuming trying to keeping the upper left for the upper left of the new sized window. If this would make the right and/or bottom go off screen, adjust the top left to compensate so that it doesn't go off screen. Adjust up to as much as topmost/leftmost of screen(no more). Same goes for if top/left is off screen too much to the top/left. move it towards the bottom/right so long as doing so wouldn't make the bottom/right go off screen.

Note: There might be some that don't like doing it this way, so it could be made optional. ( [X] Keep auto resized windows on screen[ as much as possible] )
Life is partially trying to strike a balance between generating new things/ideas, and making sure they are good/organized. These extremes can be said to between gibberish mess and nothing said/done.
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: window created twice

Post by Holger »

Just experimented a bit with fixing this issue, and just resizing the window instead of closing and re-opening it seems to work just fine, with the following changes in behavior:

If you keep the window at its initial centered position, it is not centered anymore after a size change (but keeps the same upper left corner).

On some (slower?) systems, resizing instead of re-creating the window looks better, as the window does not disappear for a very short time (revealing the background).

When the window was moved to a different screen position after it was initially created, resizing it due to changed game screen size keeps its upper left position, what is most probably what is expected. (Centering again at the old window position would be another option, but could have unwanted side effects, like having parts of the new windows off-screen. This could be checked and adjusted, but may result in problems due to window borders added by the window manager, which would also have to be taken into account then.)

Using the "just resize the window and hope for the best" approach may work surprisingly well in cases like having the window placed in the lower right corner of the screen when using an intelligent window manager. For example, KDE keeps (moves) the resized window (larger or smaller than before) to be perfectly aligned in the lower right corner again (while the latest macOS fails miserably here (as expected) by just keeping the previous upper left corner and putting the larger parts of the window off-screen).
Post Reply