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

GUI2: harden theme definition parsing #9974

Merged
merged 4 commits into from
Mar 2, 2025
Merged

GUI2: harden theme definition parsing #9974

merged 4 commits into from
Mar 2, 2025

Conversation

Vultraz
Copy link
Member

@Vultraz Vultraz commented Mar 1, 2025

  • Ensure current_gui is a valid iterator after calling init(). It should match default_gui
  • Ensure current_gui is always set to guis.end() if the requested theme isn't found in switch_theme(). It's initialized as such in gui_definition.cpp, but we shouldn't rely on that always being the case, especially in a function that changes it.
  • Only create one schema validator for all themes. Previously, it would have been created anew for each addon with a custom theme.
  • Add explicit exception handling for an invalid schema path or invalid gui2 entry point
  • Add explicit warning for addon themes with the id "default"
  • Catch wml_exception when creating gui_definition objects for all themes (previously, this was only caught for add-on themes)
  • Adjust error messages
  • Fix duplicate theme errors when reloading cache (addresses one part of Improve GUI2 theme encapsulation #9781). GUI2 definition changes now take effect without the need to restart the entire game. A cache reload is sufficient.
  • Use _main.cfg for core theme entry points
  • Include macros at global core GUI2 score instead of only in the default theme (they were always available to both themes, this just makes that clearer)

- Ensure current_gui is a valid iterator after calling init(). It should match default_gui
- Ensure current_gui is always set to guis.end() if the requested theme isn't found in switch_theme(). It's initialized as such in gui_definition.cpp, but we shouldn't rely on that always being the case, especially in a function that changes it.
- Only create one schema validator for all themes. Previously, it would have been created anew for each addon with a custom theme.
- Add explicit exception handling for an invalid schema path
- Add explicit warning for addon themes with the id "default"
- Catch `wml_exception` when creating gui_definition objects for core themes (previously, this was only caught for add-on themes)
- Fix duplicate theme errors when reloading cache (addresses one part of #9781)
- Use `_main.cfg` for core theme entry points
- Include macros at global core GUI2 score instead of only in the default theme (they were always available to both themes, this just makes that clearer)
@github-actions github-actions bot added the UI User interface issues, including both back-end and front-end issues. label Mar 1, 2025
@Vultraz Vultraz merged commit 55dc0a8 into master Mar 2, 2025
18 checks passed
@Vultraz Vultraz deleted the gui2-init-harden branch March 2, 2025 05:12
@soliton-
Copy link
Member

soliton- commented Mar 3, 2025

Note that no other schema validator use is re-using an instance. I'm going to assume this was throughly tested.

Vultraz added a commit that referenced this pull request Mar 5, 2025
Resolves #9973. Reworks #9974, since I misunderstood how schema validators worked. They are indeed stateful and you need one instance per read call.

I also decided to do away with the global macro context because I do *not* want to have to deal with people claiming the core GUI2 macros constitute a public API (nor do we want macros from one addon affecting the themes in another in the unlikely event that multiple people make gui2 themes.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI User interface issues, including both back-end and front-end issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants