Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Ensure fonts are loaded after _ready by triggering an empty update. #28

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

setzer22
Copy link
Owner

@setzer22 setzer22 commented Nov 6, 2021

Egui only builds fonts at the start of the next frame, so if the theme is loaded on _ready, the font texture won't be updated until the first GodotEgui::update, which means that a GUI that draws their first frame after some time (e.g. when a menu is first shown) will cause a noticeable hiccup.

This would also cause issues if you want to add some extra fonts after loading a theme. After calling _ready on a GodotEgui object, trying to access egui.fonts().definitions() would return the old value, not the one set by the theme.

Triggering an empty update takes care of the problem with no noticeable side effects.

@setzer22
Copy link
Owner Author

setzer22 commented Nov 6, 2021

It seems the rustfmt.toml file that was included on the repo depends on some nightly features and CI does not like that.

None of these are particularly important, so I will replace the rustfmt.toml with one that runs on stable rust.

@setzer22
Copy link
Owner Author

setzer22 commented Nov 6, 2021

Strange 🤔 There seems to be an issue unrelated to my changes: https://github.com/setzer22/godot-egui/runs/4127143647?check_suite_focus=true

 error[E0277]: the trait bound `Arc<Style>: From<egui::style::Style>` is not satisfied
 Error:    --> godot_egui/src/lib.rs:224:47
    |
 224 | ...                   self.egui_ctx.set_style(style);
     |                                     ^^^^^^^^^ the trait `From<egui::style::Style>` is not implemented for `Arc<Style>`

But the code compiles and builds fine on my machine. I'll try removing my local Cargo.lock to see if I can reproduce.

EDIT: Indeed, looks like a library bump issue. It looks like it may be updating to egui 0.15 even if we specified a hard dependency on 0.14.2 (?).

Here's my old Cargo.lock file (works):

[[package]]
name = "egui"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b403f29d592b5c2267279bfdf2cd3fe3ba0e7a8738d03203a6f1536e8e9d26bd"
dependencies = [
 "epaint",
 "ron",
 "serde",
]

And here's the new Cargo.toml file that is generated if I remove the old one:

[[package]]
name = "egui"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b403f29d592b5c2267279bfdf2cd3fe3ba0e7a8738d03203a6f1536e8e9d26bd"
dependencies = [
 "epaint 0.14.0",
]

[[package]]
name = "egui"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c8d416a3343cbfc6f4d17bb1cba46b4d7efecb9ee541967763e0b5e04e5fae7"
dependencies = [
 "ahash",
 "epaint 0.15.0",
 "nohash-hasher",
 "serde",
]

I don't understand the two egui references there 🤔 Perhaps something wrong in our dependency graph?

@jacobsky Could it be egui_stylist depending on 0.15.0 perhaps? Any other ideas otherwise?

@setzer22
Copy link
Owner Author

setzer22 commented Nov 6, 2021

Here's the output of cargo-tree

godot_egui v0.1.8 (/home/josep/Repositories/godot-egui/godot_egui)
├── egui v0.14.2
│   └── epaint v0.14.0
│       ├── ab_glyph v0.2.11
│       │   ├── ab_glyph_rasterizer v0.1.5
│       │   └── owned_ttf_parser v0.12.1
│       │       └── ttf-parser v0.12.3
│       ├── ahash v0.7.6
│       │   ├── getrandom v0.2.3
│       │   │   ├── cfg-if v1.0.0
│       │   │   └── libc v0.2.106
│       │   ├── once_cell v1.8.0
│       │   └── serde v1.0.130
│       │       └── serde_derive v1.0.130 (proc-macro)
│       │           ├── proc-macro2 v1.0.32
│       │           │   └── unicode-xid v0.2.2
│       │           ├── quote v1.0.10
│       │           │   └── proc-macro2 v1.0.32 (*)
│       │           └── syn v1.0.81
│       │               ├── proc-macro2 v1.0.32 (*)
│       │               ├── quote v1.0.10 (*)
│       │               └── unicode-xid v0.2.2
│       │   [build-dependencies]
│       │   └── version_check v0.9.3
│       ├── atomic_refcell v0.1.8
│       ├── emath v0.14.0
│       └── ordered-float v2.8.0
│           └── num-traits v0.2.14
│               [build-dependencies]
│               └── autocfg v1.0.1
├── egui-theme v0.1.1
│   ├── base64 v0.13.0
│   ├── egui v0.15.0
│   │   ├── ahash v0.7.6 (*)
│   │   ├── epaint v0.15.0
│   │   │   ├── ab_glyph v0.2.11 (*)
│   │   │   ├── ahash v0.7.6 (*)
│   │   │   ├── atomic_refcell v0.1.8
│   │   │   ├── emath v0.15.0
│   │   │   │   └── serde v1.0.130 (*)
│   │   │   ├── nohash-hasher v0.2.0
│   │   │   └── serde v1.0.130 (*)
│   │   ├── nohash-hasher v0.2.0
│   │   └── serde v1.0.130 (*)
│   └── serde v1.0.130 (*)
├── gdnative v0.9.3
│   ├── gdnative-bindings v0.9.3
│   │   ├── bitflags v1.3.2
│   │   ├── gdnative-core v0.9.3
│   │   │   ├── ahash v0.7.6 (*)
│   │   │   ├── approx v0.4.0
│   │   │   │   └── num-traits v0.2.14 (*)
│   │   │   ├── bitflags v1.3.2
│   │   │   ├── euclid v0.22.6
│   │   │   │   └── num-traits v0.2.14 (*)
│   │   │   ├── gdnative-impl-proc-macros v0.9.3 (proc-macro)
│   │   │   │   ├── proc-macro2 v1.0.32 (*)
│   │   │   │   ├── quote v1.0.10 (*)
│   │   │   │   └── syn v1.0.81 (*)
│   │   │   ├── gdnative-sys v0.9.3
│   │   │   │   └── libc v0.2.106
│   │   │   │   [build-dependencies]
│   │   │   │   ├── bindgen v0.56.0
│   │   │   │   │   ├── bitflags v1.3.2
│   │   │   │   │   ├── cexpr v0.4.0
│   │   │   │   │   │   └── nom v5.1.2
│   │   │   │   │   │       └── memchr v2.4.1
│   │   │   │   │   │       [build-dependencies]
│   │   │   │   │   │       └── version_check v0.9.3
│   │   │   │   │   ├── clang-sys v1.3.0
│   │   │   │   │   │   ├── glob v0.3.0
│   │   │   │   │   │   ├── libc v0.2.106
│   │   │   │   │   │   └── libloading v0.7.1
│   │   │   │   │   │       └── cfg-if v1.0.0
│   │   │   │   │   │   [build-dependencies]
│   │   │   │   │   │   └── glob v0.3.0
│   │   │   │   │   ├── lazy_static v1.4.0
│   │   │   │   │   ├── lazycell v1.3.0
│   │   │   │   │   ├── peeking_take_while v0.1.2
│   │   │   │   │   ├── proc-macro2 v1.0.32 (*)
│   │   │   │   │   ├── quote v1.0.10 (*)
│   │   │   │   │   ├── regex v1.5.4
│   │   │   │   │   │   └── regex-syntax v0.6.25
│   │   │   │   │   ├── rustc-hash v1.1.0
│   │   │   │   │   └── shlex v0.1.1
│   │   │   │   ├── miniserde v0.1.13
│   │   │   │   │   ├── itoa v0.4.8
│   │   │   │   │   ├── mini-internal v0.1.13 (proc-macro)
│   │   │   │   │   │   ├── proc-macro2 v1.0.32 (*)
│   │   │   │   │   │   ├── quote v1.0.10 (*)
│   │   │   │   │   │   └── syn v1.0.81 (*)
│   │   │   │   │   └── ryu v1.0.5
│   │   │   │   ├── proc-macro2 v1.0.32 (*)
│   │   │   │   └── quote v1.0.10 (*)
│   │   │   ├── indexmap v1.7.0
│   │   │   │   └── hashbrown v0.11.2
│   │   │   │   [build-dependencies]
│   │   │   │   └── autocfg v1.0.1
│   │   │   ├── libc v0.2.106
│   │   │   └── parking_lot v0.11.2
│   │   │       ├── instant v0.1.12
│   │   │       │   └── cfg-if v1.0.0
│   │   │       ├── lock_api v0.4.5
│   │   │       │   └── scopeguard v1.1.0
│   │   │       └── parking_lot_core v0.8.5
│   │   │           ├── cfg-if v1.0.0
│   │   │           ├── instant v0.1.12 (*)
│   │   │           ├── libc v0.2.106
│   │   │           └── smallvec v1.7.0
│   │   ├── gdnative-sys v0.9.3 (*)
│   │   └── libc v0.2.106
│   │   [build-dependencies]
│   │   ├── gdnative_bindings_generator v0.9.3
│   │   │   ├── heck v0.3.3
│   │   │   │   └── unicode-segmentation v1.8.0
│   │   │   ├── miniserde v0.1.13 (*)
│   │   │   ├── proc-macro2 v1.0.32 (*)
│   │   │   ├── quote v1.0.10 (*)
│   │   │   ├── roxmltree v0.14.1
│   │   │   │   └── xmlparser v0.13.3
│   │   │   ├── syn v1.0.81 (*)
│   │   │   └── unindent v0.1.7
│   │   └── heck v0.3.3 (*)
│   ├── gdnative-core v0.9.3 (*)
│   └── gdnative-derive v0.9.3 (proc-macro)
│       ├── proc-macro2 v1.0.32 (*)
│       ├── quote v1.0.10 (*)
│       └── syn v1.0.81 (*)
└── ron v0.6.6
    ├── base64 v0.13.0
    ├── bitflags v1.3.2
    └── serde v1.0.130 (*)

godot_egui_example v0.1.0 (/home/josep/Repositories/godot-egui/example_project)
├── egui v0.14.2 (*)
├── egui_demo_lib v0.14.0
│   ├── egui v0.14.2 (*)
│   ├── epi v0.14.0
│   │   └── egui v0.14.2 (*)
│   └── unicode_names2 v0.4.0
├── gdnative v0.9.3 (*)
└── godot_egui v0.1.8 (/home/josep/Repositories/godot-egui/godot_egui) (*)

godot_egui_stylist v0.1.0 (/home/josep/Repositories/godot-egui/egui_stylist_addon)
├── anyhow v1.0.45
├── egui v0.14.2 (*)
├── egui-stylist v0.1.1
│   ├── base64 v0.13.0
│   ├── egui v0.15.0 (*)
│   ├── egui-theme v0.1.1 (*)
│   └── serde v1.0.130 (*)
├── egui-theme v0.1.1 (*)
├── gdnative v0.9.3 (*)
├── godot_egui v0.1.8 (/home/josep/Repositories/godot-egui/godot_egui) (*)
├── ron v0.6.6 (*)
└── serde v1.0.130 (*)

Turns out cargo was picking egui-theme 0.1.1 even if we specified 0.1.0 on godot_egui's Cargo.toml. This lead to a dependency mismatch where egui 0.14.2 and 0.15.1 were both selected at the same time.

It seems cargo will not respect dependencies specified as "0.1.0" and will freely bump the revision number. The fix was to change the depencency to "=0.1.0", which temporarily fixes the issue until we bump egui here (which should be soon, anyway).

@jacobsky
Copy link
Collaborator

jacobsky commented Nov 7, 2021

Ah, yeah. Sorry about that! The 0.1.1 part was to update it to work with egui 0.15.x since there were some breaking changes that needed to work.

I didn't realize that we could pin the "exact" version in that way. I'll make sure to do that in the future on the 0.15.0 PR.

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

Successfully merging this pull request may close these issues.

None yet

2 participants