Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)

Started by Trevor Williams Jan 2, 2015 at 3:23 AM 2 replies 3.4k views
Original Post
Trevor Williams
Trevor Williams

int

SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)

{

CHECK_DISPLAY_INDEX(displayIndex, -1);

if (rect) {

...... omitted code ........

}

return 0;

}

If rect is initialized to NULL, nullptr, or is just garbage, SDL_GetDisplayBounds still returns the success code, 0. Is there a reason for this or is it a mistake? Would ask on the libsdl forums, but I haven't gained write access there yet.

"You all look like lions to me.  Lets be rabbits again." Request for Comments => https://github.com/ts-williams
swiftcoder
swiftcoder

That isn't a bug, the function is intended to work that way.

If you pass in NULL, then you have clearly specified that you don't need the actual bounds value, so it would not be reasonable to return an error code in this case. The return code will still indicate whether the display index you passed in is valid, so it may well be reasonable to call this function with an argument of NULL.

(many C APIs work this way, where more modern APIs tend to go out of their way to detect programmer idiocy)

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
rip-off
rip-off

That isn't a bug, the function is intended to work that way.

Seems surprising that a function to get the display bounds makes that an optional return value! That said, SDL tries to be consistent, and other functions that output parameters typically make them optional.

The return code will still indicate whether the display index you passed in is valid, so it may well be reasonable to call this function with an argument of NULL.

Probably would be clearer to use SDL_GetNumVideoDisplays() in that case.

Would ask on the libsdl forums, but I haven't gained write access there yet.

SDL definitely has a mailing list.
Trevor Williams
Trevor Williams

Yeah, I thought it was strange a function called SDL_GetDisplayBounds can return normally if it can't get the display bounds too. I'm also wondering if it can really be trusted to validate a display index. The macro CHECK_DISPLAY_INDEX it calls doesn't return abnormally only if the display index is invalid. It returns abnormally if the video subsystem hasn't been initialized too. In other words the index could be good, but you still get an error if the state of the video subsystem is bad. Passing Null is valid for other SDL functions, but it's documented in the headers in their cases. Makes more sense to me too because most manipulate more than one value. If you don't care about one of two, passing Null for that one and still succeeding as long as the other makes it through makes sense. But....I don't know. I'm just going to be careful how I use SDL_GetDisplayBounds

"You all look like lions to me.  Lets be rabbits again." Request for Comments => https://github.com/ts-williams

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.