Remove bugprone sf::Text constructor#2486
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2486 +/- ##
==========================================
- Coverage 29.14% 23.60% -5.54%
==========================================
Files 187 212 +25
Lines 15610 18658 +3048
Branches 3789 4457 +668
==========================================
- Hits 4549 4405 -144
- Misses 10667 13758 +3091
- Partials 394 495 +101
... and 81 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
502f0b2 to
1ad7841
Compare
Bromeon
left a comment
There was a problem hiding this comment.
Repeating my comment from here:
A case we need to think about:
sf::Text text(font); addText(std::move(text)); // give ownership away // now `text` is like a "default-constructed" instance -- what are its semantics?Also,
sf::Fontrelates tosf::Textthe same way thatsf::Texturerelates tosf::Sprite, orsf::SoundBuffertosf::Sound. What do you think about those resources?
This will force users to use std::optional<sf::Text> in classes that use text that cannot be immediately initialized -- which is probably a good thing to highlight nullability. But we might need to check user feedback here.
On a tangential note, in retrospective I think removing the default font was a user-unfriendly decision. Sure, it keeps the binary smaller, but it's quite a bit of extra effort to get some simple text or debug info displayed. It's probably in line though with seeing SFML as a more mid-level media abstraction, rather than a "batteries included" sort of game engine.
I'm also open to the idea of bringing back a default font should someone choose to lead that effort. It's very user-friendly to not require everyone load their own font. It's in line with how we vendor all dependencies instead of making users supply them. |
|
Regarding moved-from types, that's a good point. We define |
Exactly. We can basically define the "moved-from" state in two ways:
I'm also totally OK when going with (1) -- in that case we wouldn't need a default constructor, as it's not part of the public API to reuse "empty" |
I don't believe we can make any changes to the library to make such bugs easier to detect. It's squarely on users to not use moved-from objects.
I'm inclined to stick to (1). As far as I'm aware, our intent with adding more move semantics is to elide copies for the sake of performance. It's worth bearing in mind that if we start with option (1), we can always make moved-from objects more defined in the future, but if we promise that a given moved-from object is safe to use without reinitializing, we can't rescind that promise without breaking the API. (1) is the lazy option that gives us more leeway going forward. |
|
I'm generally in favour of this change.
I'm also in favour of this approach.
No, but we could track these things at run-time in debug mode. Would probably not be worth the extra code complexity added. |
vittorioromeo
left a comment
There was a problem hiding this comment.
Some minor readability changes.
4301175 to
d278b06
Compare
|
Thanks for the feedback. I used structured bindings to get rid of all those double lookups. By the way, here are some more places we can use structured bindings. Might submit a PR if others are eager to use structured bindings in more places. |
d278b06 to
221eb2a
Compare
Description
Closes #2194
The default constructor for
sf::Textmade it possible to accidentally forget to assign a font. Removing that default constructor means users are forced to supply a font makingsf::Textharder to misuse. While I was at it, I also tweaked the existing constructor to allow users to specify a font without a default string to avoid the needless""argument.This required some changes to the Joystick example which made heavy use of default constructed text objects. The modifications to that example prove that a default constructor is not required to effectively use
sf::Text.