BlindMindStudios / StarRuler2-Source

4X Space Strategy game Star Ruler 2's open source distribution.
http://starruler2.com
Other
1.46k stars 246 forks source link

Remove unnecessary null pointer checks #11

Open elfring opened 6 years ago

elfring commented 6 years ago

An extra null pointer check is not needed in functions like the following.

ThyReaper commented 6 years ago

If you'd like to improve these sorts of checks, we do welcome pull requests.

That second request is not redundant: glDeleteProgram is a potentially expensive call even in the case of a 0 id.

AtlaStar commented 6 years ago

That second request is not redundant: glDeleteProgram is a potentially expensive call even in the case of a 0 id.

I am curious about this, as the documents on khronos for OpenGL explicitly state that passing 0 will be silently ignored by glDeleteProgram. The only assumption I could make is that it has to do with the assumed cost of the call versus the logic check, no? If that isn't the concern then removing the unnecessary check should be fine I would assume.

ThyReaper commented 6 years ago

That second request is not redundant: glDeleteProgram is a potentially expensive call even in the case of a 0 id.

I am curious about this, as the documents on khronos for OpenGL explicitly state that passing 0 will be silently ignored by glDeleteProgram. The only assumption I could make is that it has to do with the assumed cost of the call versus the logic check, no? If that isn't the concern then removing the unnecessary check should be fine I would assume.

In practice, it's dangerous to rely on the OpenGL docs. I vaguely remember this sort of call outright crashing on a particular Intel driver, for example.

Regardless, those docs only say it will be silently ignored, not how. If the call is still passed to the GPU, rather than being filtered at the API call level, it can still be expensive.

elfring commented 6 years ago

…, those docs only say it will be silently ignored, not how.

ThyReaper commented 6 years ago

…, those docs only say it will be silently ignored, not how.

  • How do you think about to achieve a better wording there anyhow?
  • Can it usually mean that an immediate return will be performed by these functions after the input parameter validation?

In the docs? It's a moot point. Implementations in the wild do whatever they feel like, and the docs only loosely describe the behavior most of the time. Relying on 'usually' is what causes most issues in OpenGL titles.