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

Author Topic: VertexArray append creating extra vertices  (Read 1852 times)

0 Members and 1 Guest are viewing this topic.

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
VertexArray append creating extra vertices
« on: November 11, 2017, 03:53:22 pm »
I ran into something weird while merging 2 vertex arrays:

I have an empty vertex array called "vaInterface", and a vertexarray called just "va" in a class called "PanelBottom" with a size of 4. Both are quads. I append "va" and the size of "vaInterface" becomes 8! code:

std::cout << vaInterface.getVertexCount() << std::endl; // PRINTS 0
std::cout << objPanelBottom.va.getVertexCount() << std::endl; // PRINTS 4
std::cout << vaInterface.getVertexCount() + objPanelBottom.va.getVertexCount() << std::endl; // PRINTS 4

vaInterface.resize(vaInterface.getVertexCount() + objPanelBottom.va.getVertexCount());
for (unsigned int i = 0; i < objPanelBottom.va.getVertexCount(); i++)
{
    vaInterface.append(objPanelBottom.va[i]);
}

std::cout << vaInterface.getVertexCount() << std::endl; // PRINTS 8
 

If I then print the positions of each vertex, the first 4 are all 0s. 5 through 8 are positioned correctly.

Anyone know why this is?

edit: VertexCount keeps doubling when I append other vertexarrays to vaInterface. I added another vertexarray with size 4 and now the total size is 16 when it should be 8.
« Last Edit: November 11, 2017, 04:01:37 pm by NGM88 »

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: VertexArray append creating extra vertices
« Reply #1 on: November 11, 2017, 04:13:29 pm »
i guess append resizes your vaInterface. so you have 8 = resize(4) + 4 * append(1).

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: VertexArray append creating extra vertices
« Reply #2 on: November 11, 2017, 04:32:46 pm »
i guess append resizes your vaInterface. so you have 8 = resize(4) + 4 * append(1).

Thanks, that makes sense. Definitely doesn't say that in the documentation though.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10989
    • View Profile
    • development blog
    • Email
Re: VertexArray append creating extra vertices
« Reply #3 on: November 11, 2017, 04:59:09 pm »
Neither does it say you need to resize your vertex array first before inserting. ;)

Append is a very common function name and that it automatically adjusts the target container is an assumption you'll find for pretty much any container that implements an append function in pretty much any programming language.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/