Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Some surface updates #108

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Vraiment
Copy link
Contributor

Implementations for issue #80 , also updated some comments and removed the flags in the constructor that has them as argument, there is no reason to request the user for the flags if they should be put to zero anyway.

@@ -41,16 +41,33 @@ Surface::Surface(SDL_Surface* surface) : surface_(surface) {
assert(surface);
}

Surface::Surface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) {
if ((surface_ = SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask)) == nullptr)
Surface::Surface(int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) {
Copy link
Member

Choose a reason for hiding this comment

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

SDL does doesn't say it's obsolete. Flags could be unused now, but will be at some point. Also, breaking API is bad, m'kay. Could add a thin wrapper, but I don't think the complication is worth this single argument.

}

Surface::Surface(void* pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) {
if ((surface_ = SDL_CreateRGBSurfaceFrom(pixels, width, height, depth, pitch, Rmask, Gmask, Bmask, Amask)) == nullptr)
throw Exception("SDL_CreateRGBSurfaceFrom");
}

#if SDL_VERSION_ATLEAST(2, 0, 5)
Surface::Surface(int width, int height, int depth, Uint32 format) {
Copy link
Member

Choose a reason for hiding this comment

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

Here SDL docs do say it's obsolete, but it really looks strange, since SDL_CreateRGBSurfaceWithFormat was just introduced. Again, I'd stick with upstream API, for consistency, ease of migration and avoiding potential problems in future.

#if SDL_VERSION_ATLEAST(2, 0, 5)
Surface::Surface(int width, int height, int depth, Uint32 format) {
// Flags are obsolete and should be set to 0 according to the documentation
if ((surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth, format)) == nullptr) {
Copy link
Member

Choose a reason for hiding this comment

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

Note that my code style avoids {}'s for single line statements.

Copy link
Contributor Author

@Vraiment Vraiment Jul 26, 2017

Choose a reason for hiding this comment

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

I general I just agree with your style despite some of it is not what I like/think is better in the base that it would be just be long opinionated discussions, but here I will push back.

After the #gotofail issue from some years back I consider is a good practice to put braces around the code you are making conditional, even if is just one line.

I know this won't cause a security hole that will impact such a big range of users, but still, is good to say when the if should end, is just two extra characters one extra line

Copy link
Member

Choose a reason for hiding this comment

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

Well the code style is not written in stone and I may reconsider it of there's good enough reason (this copypasta bug does not convince me here though), but my main point here is that whatever it is, it must be consistent all over the project code.


#ifdef SDL2PP_WITH_IMAGE
////////////////////////////////////////////////////////////
/// \brief Create surface loading it via RWops
///
/// \param[in] rwops RWops used to access an image file
///
/// \throws SDL2pp::Exception
Copy link
Member

Choose a reason for hiding this comment

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

Separate PR, please.

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

Successfully merging this pull request may close these issues.

2 participants