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
Return reference instead of non-null pointer #2637
Return reference instead of non-null pointer #2637
Conversation
and do some simplification using the fact that a constructed sprite has a non-null texture pointer.
because a the m_font pointer cannot be null.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2637 +/- ##
========================================
Coverage 28.73% 28.73%
========================================
Files 229 229
Lines 19755 19753 -2
Branches 4725 4724 -1
========================================
Hits 5676 5676
- Misses 13437 13584 +147
+ Partials 642 493 -149
... and 23 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this! It removes yet another potential source of bugs from the API and further reinforces the idea that SFML 3 is systematically eliminating invalid states from being representable in the type system.
https://github.com/SFML/imgui-sfml/pull/250/files Already found a real world example this is helpful. It's useful to know that a sprite always has a texture. It saves you some manual error checking. |
Since #2486 and #2494,
Sprite
andText
instances cannot hold a null pointer to the corresponding resource.I suggest that
getTexture
andgetFont
return a reference instead of a pointer to make it clear that it is not null.What do you think?
Note this is slightly changing
Sprite
constructor behavior. If I understand correctly,Sprite(texture, IntRect())
is equivalent toSprite(texture)
in master, whereasSprite(texture, IntRect())
would actually create a Sprite with an empty texture rectangle with this PR. It looks to me this would be the correct behavior one would expect.I also reviewed corresponding tests and fixed a small inconsistency in
Text
tests while at it.The same kind of change would apply to
Sound
andgetSoundBuffer
once the default constructor gets removed as planned in #2507.