-
-
Notifications
You must be signed in to change notification settings - Fork 868
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
Emscripten doesn't persist all setting changes #9208
Comments
This is not true. Many settings do in fact trigger a write to What you run into here, is that we do have a few code-paths that do not use the Settings wrapper to change a setting. These are not stored after changed, and Emscripten is feeling the effects of that. In other words, we already do have code for this in place, some lines of code are just sneaky going behind its back ;) The main issue: finding those places is difficult. This one is most likely https://github.com/OpenTTD/OpenTTD/blob/master/src/settings_gui.cpp#L2365 . But I am sure there are others that change the settings themselves instead of via the wrappers. A quick grep suggests we have roughly 83 of those instances (this will miss some instances, like These are 42 unique keys (again, there are a few more that use different syntax).
So that should be doable to fix :) |
Thanks @TrueBrain; I see that this is in fact handled in most places. I'd be happy to try and track down as many of the remaining settings I can find and submit a PR for that. I assume the proper fix is to refactor these to use |
Yeah, how to fix that .. that I was wondering about too. Maybe one of the other devs have some ideas how to approach this :D |
I wonder if I could add a simple helper function in Something like this, perhaps? void FlushSettingsChange()
{
SetWindowClassesDirty(WC_GAME_OPTIONS);
if (_save_config) SaveToConfig();
} |
Many |
No, that would be an anti-feature to me :) Currently the setting system does handle saving when it has to, but all those "illegal" writes are messing that up. Mostly why they are an issue, at least for me, is that they bypass any validation set for the setting, and any post-callback set. They just change a setting and don't tell anyone. That, to me, is the real issue here. If they just would use the right functions, everything will happen automagicaly :) So, no, please do not make a |
I've got an idea for a probably better solution where the act of (attempting) to set the setting triggers all kinds of things via Settings functions. This includes all kinds of validations, and would make changing settings from in the game's code much easier. I'm already working on parts, but it's progressing very slowly as it requires many other significant and complicated changes to happen first, and those take some time to get reviewed and accepted. Mostly as "just" adding a simple helper function to do something is not going to fix your problem, it is going to fix the symptoms you see... and by doing it that way we will keep getting symptoms (i.e. places where that simple helper function is not called). In other words, with your "solution" we will keep getting bug reports for settings that someone changed that were not saved and the likes, and that is therefor not a solution to the bug. |
Version of OpenTTD
Latest JGR commit on Emscripten, however, this is not a JGRPP-specific issue.
Expected result
openttd.cfg
settings to be persisted across refreshes.Actual result
Some settings (like the one controlling what category of settings are visible) do not appear to be persisted after the tab is closed and reopened.
This happens because many setting changes in OpenTTD do not trigger a write to
openttd.cfg
, and due to the limitations the browser environment provides, closing a tab is effectively the same as killing the OpenTTD process on Linux. Therefore, it is not possible to guarantee that settings are saved on exit like other platforms.Here are some potential solutions (in no particular order):
SaveToConfig()
call in every instance where a setting is changed.onbeforeunload
handler to prevent the user from immediately closing the page. If they click OK, the page will be closed anyway and there's nothing we can do about it, however, if they click Cancel, OpenTTD will run again and have a chance to finish saving their settings. The problem with this solution is that there is no way I see to know whether the settings needs saving or not; therefore this handler will probably be perceived as annoying.Steps to reproduce
The text was updated successfully, but these errors were encountered: