Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Shader::setUniform with bool parameter -> bug source?  (Read 2721 times)

0 Members and 1 Guest are viewing this topic.

Daid

  • Newbie
  • *
  • Posts: 29
    • View Profile
sf::Shader::setUniform with bool parameter -> bug source?
« on: November 01, 2016, 11:28:58 am »
First off, let me say I love the improvements in SFML 2.4.0, nice upgrade compared to 2.3.x on the shader interface.

However, I just spend half an hour trying to find out why my shader was not rendering with a texture. I finally found out that I was passing an sf::Texture pointer instead of a reference to the setUniform function. And, as C++ does implicit type conversions of pointers to booleans, it was calling the setUniform(name, bool) instead.

With all the new setUniform functions, maybe setUniform(name, bool) is a bit out of place due to the very easy mistake of implicit pointer casts of all the other objects you can pass as parameters to this function.


Possible ways to prevent this problem are:
  • Make the setUniform for bool more explicit -> setUniformBool. But this breaks with the rest.
  • Add a private setUniform(string name, void*), so the pointer gets implicit cast to a void pointer and thus throws a compile error.
  • Tell idiots like myself to depend less on pointers.


(I know I should prefer references. But that is not always a possibility in this case)

EDIT: I just realized. This is also inconsistent with the sf::Texture::bind API, which uses a sf::Texture pointer instead of a reference.
« Last Edit: November 02, 2016, 09:17:36 pm by Daid »

 

anything