When drawing sf::Text on android getting: "sfml-error: Could not copy vertex buffer"
Confirmed on Android 5.1, 8.0, 9.0
SFML version: 2.5.1
Compiler: clang
NDK version: 20
Compiler flags: -g -O0 -fexceptions -std=c++17
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include <vector>
int main(int argc, char *argv[])
{
sf::VideoMode screen(sf::VideoMode::getDesktopMode());
sf::RenderWindow window(screen, "");
sf::Font font;
if (!font.loadFromFile("sansation.ttf"))
return EXIT_FAILURE;
sf::View view = window.getDefaultView();
std::vector<sf::Text> displayed;
bool active = true;
while (window.isOpen())
{
sf::Event event;
while (active ? window.pollEvent(event) : window.waitEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::Escape)
window.close();
break;
case sf::Event::MouseLeft:
active = false;
break;
case sf::Event::MouseEntered:
active = true;
break;
case sf::Event::TouchBegan:
displayed.emplace_back("font",font, 40);
displayed.back().setPosition(0,displayed.size()*40);
break;
}
}
if (active)
{
window.clear();
for(auto &elem : displayed)
window.draw(elem);
window.display();
}
else {
sf::sleep(sf::milliseconds(100));
}
}
}
Correct drawing sf::Text without error.
When adding sf::Text to vector and drawing it, getting bugs with correct draw and SFML error. To reproduce this, tap on screen 4-6 times.
Even though this seems rather strange, we might be hitting some ridiculously low implementation limit on the number of supported VBOs. Regardless of the actual reason, #1584 should alleviate this issue.
@binary1248 I'd like to notice that we talk about 4-6 text instances 4 glyphs each. The limit cannot be _so_ low. I use SFML in my project and had no issues with several dozens of text instances even on Android.
Besides the number of VBOs that are created, I don't see any difference in program state between 2 taps and 4 taps, hence my assumption.
@FQLT can you run this in debug configuration with some kind of console open in the background? Any OpenGL errors that occur will be logged to the console this way.
@binary1248 Here https://pastebin.com/BAEvMMBK is full console output from android studio. SFML vertex buffer errors starts producing after several taps. I found solution for me, in std::vector I store std::string instead of sf::Text, and on draw I create instances of sf::Text from std::string and draw it.
Does this also happen if you sleep for 2 seconds after window creation? And does it happen if you add new text instances based on time rather than taps?
Does this also happen if you sleep for 2 seconds after window creation? And does it happen if you add new text instances based on time rather than taps?
Yes and yes
Besides the number of VBOs that are created, I don't see any difference in program state between 2 taps and 4 taps, hence my assumption.
I might imagine that there is a vector object (sf::Text) copying issue when the displayed vector reallocates its storage.
Android - 22

