SFML community forums

Help => Graphics => Topic started by: degski on March 22, 2019, 08:17:56 am

Title: Drawing a sf::VertexArray with some default constructed Vertices
Post by: degski on March 22, 2019, 08:17:56 am
A simple quick question [I hope].

Does drawing default constructed Vertices [in a sf::VertexArray] constitute UB and/or does it cause any other trouble?

Doing this appears to not create any problems (Debug or Release), but I just want to be sure!
Title: Re: Drawing a sf::VertexArray with some default constructed Vertices
Post by: Laurent on March 22, 2019, 09:38:13 am
Why would it be a UB? sf::Vertex is a very simple structure; a default constructed vertex is just an instance with some predefined values for position, color and texture coordinates. And since sf::Vertex has default constructor explicitly defined, those values are well defined and known.
Title: Re: Drawing a sf::VertexArray with some default constructed Vertices
Post by: degski on March 22, 2019, 10:17:42 am
I understand, there are no allocations or whatever (they're POD's basically), but I am drawing them, for some animation I will set them to some values later and then when the animation is finished, I will reset (memset) them again. The objective is to keep everything in one sf::VertexArray.
Title: Re: Drawing a sf::VertexArray with some default constructed Vertices
Post by: Hapax on March 23, 2019, 10:20:42 pm
Be aware that if you're drawing all of the vertices including the ones that are still in their default state, the shape may not be as expected as those vertices will 'pull' the shape to (0, 0).
Title: Re: Drawing a sf::VertexArray with some default constructed Vertices
Post by: degski on March 25, 2019, 09:47:18 am
Be aware that if you're drawing all of the vertices including the ones that are still in their default state, the shape may not be as expected as those vertices will 'pull' the shape to (0, 0).

I am drawing textured quads with the VertexArray, either a quad is proper (i.e. it's got position, color and texture coords) or it is completely default (all 4 vertices of a particular quad).

I hope(d) that that doesn't create any funny stuff (please comment if you have doubts over this). 
Title: Re: Drawing a sf::VertexArray with some default constructed Vertices
Post by: Laurent on March 25, 2019, 10:11:30 am
If a quad with all default-constructed vertices should appear as a white point at coordinates (0, 0).
Title: Re: Drawing a sf::VertexArray with some default constructed Vertices
Post by: degski on March 25, 2019, 11:55:40 am
If a quad with all default-constructed vertices should appear as a white point at coordinates (0, 0).

Thanks Laurent. I got my extra strong spectacles out (not kidding) and had a look. I don't see a white pixel (everything is very dark, so it should have been visible easily (with the spectacles on a 1920*1080 display).

Iff I start seeing it [the white pixel] I'm warned, thanks.
Title: Re: Drawing a sf::VertexArray with some default constructed Vertices
Post by: Laurent on March 25, 2019, 01:42:04 pm
I assumed that a quad with no area would appear as a point, but no output at all is also a possibility I guess.