Remove default sf::Sprite constructor#2494
Conversation
|
What other types may need to get this treatment? The pattern is that types that hold a raw pointer to a resource ought to not have a default constructor.
|
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2494 +/- ##
==========================================
- Coverage 27.28% 27.28% -0.01%
==========================================
Files 228 228
Lines 19639 19637 -2
Branches 4710 4709 -1
==========================================
- Hits 5358 5357 -1
- Misses 13802 13821 +19
+ Partials 479 459 -20
... and 4 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Possibly some of shapes? CircleShape (float radius=0, std::size_t pointCount=30) Are these meaningful defaults? Not necessarily. But it's important that we're all fully aware that we do restrict quite some use cases by not having things default-constructible, like:
It doesn't seem to reset to null? Lines 50 to 55 in 21af6fe Lines 89 to 102 in 21af6fe This auto-attach/detaqch seems to me more like something where we could unify the behavior of resources. It can be surprising that sound auto-unlikes itself upon destruction, while others just run into UB. I understand it's probably because sounds run continuously on a separate thread and sounds need to be centrally managed, but still...
That seems too restrictive to me. These "frontend" classes (sprite, sound, text) are relatively lightweight and I don't see why we should forbid copying. |
Line 172 in 21af6fe |
If a type can only reach a given state through its default constructor, that default constructor maybe shouldn't exist. For example, a However, an By that logic I think it's fine to let an TL;DR
|
This is a great observation, makes total sense 👍 I'm not sure if it alone is a sufficient criterion though. In contrast, a rectangle or circle with 0 extents is a degenerate case and almost never what someone wants -- even in the few hard-to-construct scenarios where someone intentionally needs this, it's always possible to explicitly provide such arguments. To be clear, I'm not saying |
3bf7e6d to
2b3e814
Compare
931d676 to
8a26616
Compare
I think it would be reasonable to force an explicit radius in many cases (but not in all of them; as a member variable it would be annoying), but I'd also consider that even with the defaulted radius of 0 the object in itself is still valid. The other calls are not failing after all. Also, using this approach, one could even question if it should be possible to default a (geometrical) vector to all zeroes, because a zero length vector would be a special edge case just like a zero radius circle. |
Is "annoying" a good enough reason though? It's also annoying to be forced to initialized
Fully disagree, zero vectors are geometrically meaningful for a huge number of cases: coordinate origin, zero offset, zero velocity, etc. They are a very reasonable default value, the same way that 0 is for |
|
But just like a zero velocity make sense (even if there's no direction), wouldn't a zero radius circle make sense? A vector is defined by length and orientation, yet a zero vector lacks a clear orientation. A circle is defined by a radius (and number of segments, technically), so would a zero radius circle still be a circle? Maybe getting a bit too philosophical…😉 I think |
8a26616 to
0f7be4a
Compare
0f7be4a to
25f1d0c
Compare
Description
Continuation of the new precedent established in #2486.