OpenTTD

Tasklist

FS#998 - Chosen resolution is not used on re-open of OTTD

Attached to Project: OpenTTD
Opened by SirkoZ (SirkoZ) - Sunday, 08 July 2007, 12:54 GMT
Last edited by Patric Stout (TrueBrain) - Monday, 06 August 2007, 20:32 GMT
Type Bug
Category Interface
Status Closed
Assigned To No-one
Operating System All
Severity High
Priority Normal
Reported Version trunk
Due in Version 0.5.3
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Revision: 0.5.3 RC2

Desc.: I play OpenTTD in 640x480 (like TTD's default res.), but my desktop is at 1024x768. When I close down the OTTD and re-run it - the screen resolution of the game is re-set to 1024x768. Quite annoying.
This task depends upon

Closed by  Loïc GUILLOUX (glx)
Thursday, 09 August 2007, 21:02 GMT
Reason for closing:  Fixed
Additional comments about closing:  in r10399
Comment by Loïc GUILLOUX (glx) - Sunday, 08 July 2007, 13:25 GMT
Did it work in 0.5.2 ?
Comment by SirkoZ (SirkoZ) - Monday, 09 July 2007, 00:15 GMT
Yes - of course.
If set at 640x480, in 0.5.2 and all the releases (apart from 0.4.0 I think) the resolution stayed at 640x480 or any other for that matter.
Comment by SirkoZ (SirkoZ) - Thursday, 12 July 2007, 18:36 GMT
Perhaps I failed to mention this was in Win2k.
Comment by KUDr (KUDr) - Saturday, 21 July 2007, 08:54 GMT
I am unable to reproduce it on WinXP (both 0.5.3-RC2 & trunk). Can you post your .cfg?
Comment by SirkoZ (SirkoZ) - Saturday, 21 July 2007, 13:05 GMT
Yes - of course.
Interesting - upon actually opening the .cfg and editing "resolution" to 640, 480 - openTTD started in 640x480 - I then closed it and when I re-ran it, it was again in 1024x768 - 1024, 768 was also written in .cfg. That is in both - trunk and RC2 0-5-3.

Here's the .cfg of my 0.5.3-RC2 and also trunk's.
Comment by Remko Bijker (Rubidium) - Monday, 30 July 2007, 10:43 GMT
Does the attached patch fix this issue?
Comment by SirkoZ (SirkoZ) - Monday, 30 July 2007, 16:34 GMT
Yes!

That move of shutdown commands to after the config is saved helped a heap! :-)

Now the set resolution, fullscreen or not, stays. Thank you.

Only one more thing though - perhaps should I open a new bug report?
When switching from full screen, with resolution other than desktop's, to window mode, the window doesn't retain its fullscreen size but is stretched to the desktop resolution and it says "other" in resolution box (again - Win2k). The other way around works ok.
Comment by Remko Bijker (Rubidium) - Tuesday, 31 July 2007, 00:36 GMT
The only way I can reproduce your 'issue' is by maximizing the window before going fullscreen. Did you do that too?
Comment by SirkoZ (SirkoZ) - Tuesday, 31 July 2007, 19:24 GMT
Nope. Anyways - your patch works for the issue reported in this bug report and I didn't say anything about going fullscreen.

If however I go _from_ full screen (640x480) to 1024x768 (my desktop res) the window doesn't retain its 640x480 size - it's stretched across the whole 1024x768. The other way around works OK.
Comment by Remko Bijker (Rubidium) - Tuesday, 31 July 2007, 19:30 GMT
The only reason I can think of why the window would be stretched is the fact that the window's state was "maximized" before going fullscreen. Otherwise the window retains the original window size; none of the code gives pointers to the Windows API calls to go from full screen to windows mode, so Windows cannot change the resolution. Unless the window state was maximized, which only occurs when it was maximized before going full screen. Even with a shutdown of OpenTTD in between.

And the reason I do not commit my patch is because it just hides the real issue; the resolution should not change when going from/to full screen. UNLESS the window was maximized.
Comment by SirkoZ (SirkoZ) - Tuesday, 31 July 2007, 19:41 GMT
First - I never maximise OpenTTD window - ever. Only with ALT+Enter - I enter into 640x480 fullscreen or out of fullscreen to 640x480 windowed.

About your not applying your patch:
Of course the default code can't work - you DO NOT save the config information before shut-down of the OpenTTD window only after - whatever logic that follows. At any rate - the patch works and I don't know bout that second issue why it would pop-up. But it does.
Comment by Remko Bijker (Rubidium) - Tuesday, 31 July 2007, 20:03 GMT
I, nor any of the other developers, can reproduce this "issue", unless we maximize the window before going full screen. Furthermore I cannot find a single line that would cause the resolution to change when the window is not in maximized state.

And without a way to reproduce it, it is impossible to fix :( Not to mention that my knowledge of windows is virtually nil.
Comment by SirkoZ (SirkoZ) - Tuesday, 31 July 2007, 20:15 GMT
I am very sorry to hear that - although I don't blame you for not knowing Win... :-)

I'd say - for the time being - with inclusion of your fs998.diff patch - you'd greatly improve the current state of affairs at least
till you or some other developer or even player come up with a better solution. ;-)
Comment by Lupin III (Lupin III) - Friday, 03 August 2007, 15:14 GMT
I can confirm the problem on WinXP with 0.5.3-RC2, r10592, r10641, r10604-ChrisIN and r10717-ChrisIN.

As long as I use the window mode, the selected resolution is remembered for the next start. The windows will always be the same size. (openttd.cfg always contains e.g. "resolution = 800,600")

When I check fullscreen in the options (from a non-maximised game window), the resolution of the monitor is immediatly changed accordingly. But after closing the game, openttd.cfg always contains the current desktop resolution (e.g. "resolution = 1280,1024") instead of the previously selected one, which is then used at the next start of the game (the fullscreen option is correctly remembered). If I manually change the resolution in the config file before starting the game, this resolution is correctly used.

(I never maximised the window in the process.)
Comment by SirkoZ (SirkoZ) - Friday, 03 August 2007, 19:24 GMT
Thank you Sansei (Lupin III)!

I hope this get's things moving. Or perhaps this patch is too radical for non-0.6.0?
Comment by Remko Bijker (Rubidium) - Friday, 03 August 2007, 19:34 GMT
As I said before, it is not a fix, it is an ugly work around which causes fixing the real bug a much lower priority, which is IMO not the way to go.

There must be some common ground for the environments that have this issue, but so far there is no knowledge about that. Without making it reproducable for the developers or someone with a little programming knowledge looking where things go wrong, it is just a very big gamble to fix the bug.
Comment by SirkoZ (SirkoZ) - Saturday, 04 August 2007, 00:25 GMT
What the blimey are you talking about?!

Just apply the patch till you get a better understanding of the problem - I mean - I already described to you exactly it lacks in behaviour if applied so it's no gamble at all - well - at least not if nothings is broken under other OS-es than Windoze which you can simply ask someone on IRC to test it... Work-around or not - tis good enough for now - for Windoze.

Oh by the way - tell to one of the developers who actually has a Windoze machine to test it in exact way as I and Sansei (Lupin III) have described.
Comment by Remko Bijker (Rubidium) - Saturday, 04 August 2007, 00:40 GMT
So, you say that *if* I do the following in Windows that I reproduce it (Windows XP, desktop resolution 1024x768, unpatched nightly from a few days ago, VMware)?
- make sure openttd.cfg is writable
- start OpenTTD non-maximised non-fullscreen
- open the "Game Options"
- select 800x600
- click on fullscreen
- close the "Game Options" menu
- close OpenTTD
- restart OpenTTD
== now OpenTTD is started in full screen ==

According to you the resolution is 1024x768. In my version the resolution is 800x600.


Ergo, I cannot reproduce it on Windows. And I've gotten the exact same report from glx, peter1138 and KUDr (the developers that actually use Windows).

It is not only not broken on non-Windowses, it is even not broken on some Windowses. Even though we use the exact same procedure to reproduce it.

So, could you please explain me how to reproduce it on my machine (or glx's, peter1138's or KUDr's machine)?
Comment by SirkoZ (SirkoZ) - Saturday, 04 August 2007, 08:17 GMT
Ahh - that's just impossible! :-(

I mean you did all the steps. Please - do 1 more try - with the OTTD resolution of 640x480 (native) in full screen.

In any case - the whole thing is that OTTD doesn't write the chosen res. in the CFG...
Comment by SirkoZ (SirkoZ) - Saturday, 04 August 2007, 08:20 GMT
I get the same results (not written in cfg) with 800x600...
Comment by Remko Bijker (Rubidium) - Saturday, 04 August 2007, 08:28 GMT
In the case of 640x480 it puts "640,480" in the resolution line of openttd.cfg and when coming from full screen the resolution of OTTD is still 640x480.
Comment by Lupin III (Lupin III) - Saturday, 04 August 2007, 13:07 GMT
It seems to be something that is really specific to some Windows settings or the hardware (although this would astonish me, as you can't call OTTD a hardware dependent game). But the only thing I consider not standard on my WinXP installation concerning the display is: I'm using the Windows classic look. And the graphics driver is the non official Omega 6.05 driver for an ATI 8500. Ok, clinging to straws now, but maybe there is some similarity?
Comment by Lupin III (Lupin III) - Saturday, 04 August 2007, 13:36 GMT
I now tried this in a vmware window, too.
0.5.2 works as expected (as it does on a "real" Windows), 0.5.3-RC2 has the same problem even in the virtual machine. I did not configure any patches, just used the zips from the downloadpage, copied the few required files into the data folder and repeated the steps. 0.5.2 works as expected, 0.5.3-RC2 does not.
Comment by Remko Bijker (Rubidium) - Saturday, 04 August 2007, 20:31 GMT
Odd, very odd. I downloaded the the same binary and could not reproduce the issue. There must be something else that is messing with it.
Comment by Remko Bijker (Rubidium) - Saturday, 04 August 2007, 20:43 GMT
Could one of you apply the attached diff to trunk, give it a test and report what it dumped to the console?
Comment by Lupin III (Lupin III) - Monday, 06 August 2007, 22:24 GMT
How can I apply this patch? I tried BuildOTTD, but it always gave me an error message that the patch file is in use by another application (which it isn't, as every other program can read and write the file). I managed to apply the patch manually with "patch -p0 < might_get_us......". While patch worked in the shell environment set up by BuildOTTD, compiling didn't. And Starting the compilation with BuildOTTD always overwrites the changes made by the patch, because it downloads the original version from the svn.
Comment by Remko Bijker (Rubidium) - Monday, 06 August 2007, 22:28 GMT
I have got absolutely no experience with BuildOTTD. I think it is best when you ask kaan about this issue, as he has written BuildOTTD and should also be able to debug the issue you are having.

As far as I am aware the patch itself is a valid one, but I think BuildOTTD expects the patch to be in a different format, but then again I've got not idea only hunches.
Comment by Lupin III (Lupin III) - Monday, 06 August 2007, 22:51 GMT
What exactly should the patch do? I think I got the game compiled with the patch now. I compiled once directly from trunk with BuildOTTD without the patch, then I build again. Normally BuildOTTD wouldn't do anything then, because all compiled files are up to date. But I applied the patch right after the SVN-check finished and before BuildOTTD started compiling. It seems to have worked as win32_v.cpp got compiled as the only file and then openttd.exe was linked again. But starting the exe doesn't give any output (I started openttd.exe from a console, too). Where would the output be?
Comment by Loïc GUILLOUX (glx) - Monday, 06 August 2007, 22:54 GMT
openttd -d should show you the output
Comment by Lupin III (Lupin III) - Monday, 06 August 2007, 23:23 GMT
Yes, this opens a second textoutput window, where debug messages are appearing, depending on the number behind -d. But there is no output from the patch above appearing (searched for the strings in the diff-file). If the output would only be after clicking the quit button in the game, then there is another problem: the text window immediately closes (it can't be redirected to any file either).
Comment by Loïc GUILLOUX (glx) - Monday, 06 August 2007, 23:26 GMT
Run convert.exe in the same dir as openttd.exe and it will convert it to a console app, so you will be able to redirect output.
Comment by Lupin III (Lupin III) - Tuesday, 07 August 2007, 01:00 GMT
Thanks, no I can capture the output. But there is non from the diff. I'm sure it is compiled into the binary, as I found the strings from printf in openttd.exe. Any ideas?
Comment by Remko Bijker (Rubidium) - Tuesday, 07 August 2007, 04:38 GMT
The idea was that you run the binary and "reproduce" the issue of this bug, i.e. go to full screen and close and restart openttd.
Comment by Lupin III (Lupin III) - Tuesday, 07 August 2007, 13:36 GMT
I tried all that, but there is no output from the diff above. I get the debug messages (YAPF, sprites, ...), but no "csc: ##, ##" or "cr: ##, ##". So the lines from the diff never seem to get executed.

Btw I managed to compile OTTD within a cygwin environment (but without png and freetype support). Even when I start the game from there the same problem exists. It's really astonishing how others can't reproduce this bug while I can observe it on WinXP, WinXP in vmware and in a cygwin environment.
Comment by Remko Bijker (Rubidium) - Tuesday, 07 August 2007, 15:15 GMT
Cygwin isn't that different from Windows; it still uses all the Windows libraries for GUIs. The difference between the vmware and non-vmware version might not be there either as I assume you're running the same Windows installation in VMware, that is: installed from the same CD.

And what does it show if you run it with the attached patch?
Comment by Lupin III (Lupin III) - Tuesday, 07 August 2007, 16:06 GMT
Now I get output. Here are two logfiles.

In one I started in 1024 windowed mode, selected fullscreen from the options (1024 fullscreen), quit the game.
In the other I started 1280 fullscreen, selected 1024 as resolution, quit the game.

Both files have an "csc 1280" at the end, which I shouldn't be there in my opinion.

If you need another sequence, tell me what to try.
Comment by Loïc GUILLOUX (glx) - Tuesday, 07 August 2007, 16:08 GMT
Next time add a .txt extension ;)
Comment by Loïc GUILLOUX (glx) - Tuesday, 07 August 2007, 21:06 GMT
Could you try the attached diff, tell us if it works or not and report what it dumped to the console?
Comment by Lupin III (Lupin III) - Tuesday, 07 August 2007, 22:24 GMT
No change.
Again like above:
1) start windowed in desired resolution, switch to fullscreen, quit
2) start fullscreen (desktop res), switch to desired resolution, quit
Comment by Remko Bijker (Rubidium) - Wednesday, 08 August 2007, 18:32 GMT
I fear we need to get that particular VMware image that was used to be able reproduce the bug. We are basically out of ideas what might be the problem and the few hunches we had did not get any (real) result.

Is there any way you can provide the image to us?
Comment by Lupin III (Lupin III) - Wednesday, 08 August 2007, 19:33 GMT
I don't think so, it's an over 10GB image.

But I tried other things by adding some printfs to win32_v.cpp and openttd.cpp. I post the log right here since it's easier to explain. I changed win32_v.cpp (which also still contains the patch from above) and openttd.cpp. The latter mostly to track where the change of resolution occurs before saving the config. The numbers are the contents of "_cur_resolution[0]" and "_cur_resolution[1]" at the given time. Again the game is started in 1280 fullscreen, then changed to 1024 fullscreen and finally closed.

"win32_v # WndProcGdi # case WM_....." are printfs at the beginning and end of the matching case of the switch statement in the WndProcGdi function. I did this because there the value of _cur_resolution is copied to/from _bck_resolution. But this didn't seem to be a problem the problem as it is only used when maximizing the window, not for fullscreen.

More important is the part in "VideoDriver_Win32::Stop". After "DestroyWindow" is called the resolution has changed (see from line "VideoDriver_Win32::Stop # 3" and "... # 4"). I couldn't split it up any further at this point, because I could find a "DestroyWindow"-function in the source (is this a Windows function?).



win32_v # WndProcGdi # case WM_SIZE: 1280x1024
win32_v # WndProcGdi # case WM_SIZE: 1280x1024
active 1, minimize 0, fullscreen 1
active 0, minimize 0, fullscreen 1
win32_v # WndProcGdi # case WM_DESTROY: 1280x1024
win32_v # WndProcGdi # case WM_DESTROY: 1280x1024
win32_v # WndProcGdi # case WM_SIZE: 1280x1024
win32_v # WndProcGdi # case WM_SIZE: 1280x1024
active 1, minimize 0, fullscreen 1
openttd # before _video_driver->Stop(): 1024x768
win32_v # VideoDriver_Win32::Stop # 1: 1024x768
win32_v # VideoDriver_Win32::Stop # 2: 1024x768
win32_v # VideoDriver_Win32::Stop # 3: 1024x768
active 0, minimize 0, fullscreen 1
win32_v # WndProcGdi # case WM_SIZE: 1024x768
win32_v # WndProcGdi # case WM_SIZE: 1024x768
win32_v # WndProcGdi # case WM_DESTROY: 1280x1024
win32_v # WndProcGdi # case WM_DESTROY: 1280x1024
win32_v # VideoDriver_Win32::Stop # 4: 1280x1024
win32_v # VideoDriver_Win32::Stop # 5: 1280x1024
win32_v # VideoDriver_Win32::Stop # r: 1280x1024
openttd # after _video_driver->Stop(): 1280x1024
opentdd # if (save_config): Saving CFG...
Comment by Loïc GUILLOUX (glx) - Wednesday, 08 August 2007, 19:48 GMT
Please attach your patch so I can try it. I'd like to compare the outputs.
Comment by Remko Bijker (Rubidium) - Wednesday, 08 August 2007, 19:51 GMT
Can I conclude from your report that WM_SIZE is called from DestroyWindow (i.e. after DestroyWindow was called but before it returned)?
Comment by Lupin III (Lupin III) - Wednesday, 08 August 2007, 20:22 GMT
Rubidium: yes, it seems so.

I never created a patch file (always applied them), so I hope this is working.
Comment by Loïc GUILLOUX (glx) - Wednesday, 08 August 2007, 20:26 GMT
Hehe, will be easier for you to use "svn diff" next time :) (and for us too ;) )
Comment by Remko Bijker (Rubidium) - Wednesday, 08 August 2007, 22:30 GMT
If I read the documentation right WM_SIZE shouldn't be called when destroying a window; it says it calls the window proc with two other constants, but not with WM_SIZE. So somehow Windows is not behaving as it is documented to behave.

Could you check how your Windows reacts on the attached patch?
Comment by Remko Bijker (Rubidium) - Thursday, 09 August 2007, 05:35 GMT
It's likely that the patch won't compile; you just need to replace the return with return 0.
Comment by Lupin III (Lupin III) - Thursday, 09 August 2007, 12:40 GMT
"replace the return with return 0" Already did that ;-)

Other resolitions are saved with this patch, but the behaviour is a little complicated to describe now. If I start the game in 1280f and switch to 1024f the resolution changes, but the size of the game window doesn't. It is still 1280 although you can't see parts of it because they are off screen (and the starting menu is off center for example). The same goes the other way round from 1024f to 1280f, the resolution changes to 1280 but the game stays 1024. The windows desktop can be seen below and right of the game. The game still is in fullscreen mode, there are no window controls.

Second: If I start the game 1280f, switch to 1024f and quit, the config will still contain 1280. The same the other way round again. Starting 1024f, switching to 1280f, quitting, gives 1024 in the cfg. So the game size, which stays the same with this method as described above, is saved.

To actually get the right resolution saved, you have to changed to windowed mode, change the resolution, then switch to fullscreen again. But with this method you can't set a resolution bigger than the desktop resolution, actually not even the desktopn resolution itself. Windows doesn't allow a window that's larger than the desktop minus the window title bar. So if I select 1280x1024 in window mode the, the resolution in OTTD switches to "other" and actually gets set to 1280x1009 and saved. At this point the game will always start in window mode, because this is an invalied fullscreen resolution.
Comment by Loïc GUILLOUX (glx) - Thursday, 09 August 2007, 14:19 GMT
Ok let's get some more output :)
Comment by Lupin III (Lupin III) - Thursday, 09 August 2007, 15:46 GMT
Done!

Btw. Thanks for all this effort for such a little bug. I hope there aren't any other serious things held back!
Comment by Loïc GUILLOUX (glx) - Thursday, 09 August 2007, 16:21 GMT
And another try to fix this bug :)
Comment by Lupin III (Lupin III) - Thursday, 09 August 2007, 17:11 GMT
Yes, this did it! The game starts in the resolution that was used when closing it. I see what the fix is, but any idea why this only happens on certain Windowses? Maybe the language? All versions I used to test were german versions (but different SP Levels).

Loading...