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

Do not assume font handle is present in assets. #490

Merged
merged 1 commit into from
Sep 19, 2020
Merged

Do not assume font handle is present in assets. #490

merged 1 commit into from
Sep 19, 2020

Conversation

BorisBoutillier
Copy link
Contributor

This is a tentative fix for #489

Code changed to not do anything if the font handle is not yet present in the assets resource, removing the panicking 'unwraps'.

Not sure if this is the correct, as there could a design assumption broken before arriving to this pieces of code, and I am not yet fluent enough in bevy to know that.

This fixes both testcases ( late loading of font, or referencing inexistent fonts).

@BorisBoutillier
Copy link
Contributor Author

Should I also propose a CHANGELOG.md modification ?

I wonder if this is the correct way to do, adding lines in changelog in the PR themselves, as this will surely creates conflicts when two PR are merged that both add lines changelog. Needing a rebase and merge fix for the second applied one.

@Moxinilian Moxinilian added A-Assets Load files from disk to use for things like images, models, and sounds P-Crash A sudden unexpected crash labels Sep 14, 2020
@memoryruins
Copy link
Contributor

memoryruins commented Sep 14, 2020

Should I also propose a CHANGELOG.md modification ?

If you would like, I think it's okay, but that's a good point about merge conflicts. I wouldn't mind adding this to the changelog after the fix merges. I currently have a branch with some changelog updates https://github.com/memoryruins/bevy/blob/changes/CHANGELOG.md. It's a few days out of date, but I'll update it and open a PR with it soon.

edit: heh, yea, updating branch and it does seem very prone to conflicts. Since PRs are squashed into master these days, it's fairly easy to follow the chronology and update the changelog after the fact, and it's less to distract from PRs.

@cart
Copy link
Member

cart commented Sep 14, 2020

This also fixes #112.

Changelog policy is still TBD as we find out what works. For now, lets make it a separate change.

Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to go once merge conflicts are resolved

@BorisBoutillier
Copy link
Contributor Author

Merge conflicts have been resolved.

&glyph_texture,
) {
panic!("could not add character to newly created FontAtlas");
if let Some(font) = fonts.get(&self.font) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative, you could make an early return here in case the font doesn't exist yet. This way the rest of the function isn't indented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would require this:

if fonts.get(&self.font).is_some() { return; }
let font = self.fonts.get(&self.font).unwrap();

Which is both a double hash, slightly less safe, and less idiomatic. I definitely love flattening out indentation, but im not sure thats the right call here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple way is:

let font = if let Some(font) = fonts.get(&self.font) { font } else { return };

container_size: node.size,
};
drawable_text.draw(&mut draw, &mut draw_context).unwrap();
if let Some(font) = fonts.get(&text.font) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, a continue would have the same effect without indenting the whole block

@cart
Copy link
Member

cart commented Sep 19, 2020

I'm merging this now as I think its important for the 0.2.0 release happening today. @TheNeikos I'll address your code style comments in a follow up pr.

@cart cart merged commit b9f18ef into bevyengine:master Sep 19, 2020
@cart cart mentioned this pull request Sep 21, 2020
mrk-its pushed a commit to mrk-its/bevy that referenced this pull request Oct 6, 2020
@nicoburns nicoburns mentioned this pull request Oct 18, 2023
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds P-Crash A sudden unexpected crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants