Fixed both issues
Now the entries in the vertex map will stay forever, even if never used again by the sf::Text instance.
EDIT: Perhaps you have missed the
elusive line that frees the entire vertex map on calls to
Text::setFont()? If that's what you were looking for, then I can add this line also to
Text::setCharacterSize() and I think it will work fine. Anyway, below you may find my reasoning for the current implementation.
/EDITMy rationale for this particular point along the performance/memory/code complexity tradeoff in
sf::Text stemmed from assumptions regarding the most likely scenario of
sf::Text instances reuse.
More specifically:
1. Allocations (~120 bytes per char) are
reused in all the following cases:
- change in text string
- change in color
- change in text style (underline/strike-through/italics/bold)
2. Allocations are
not reused in case of:
3. And lastly, all allocations are
freed on:
I assumed that if anything in the
sf::Text instance changes between
draw() calls, it will most likely belong to group (1) above. And that the likelihood of changing (2) without changing (3) is low. And that anyway, while changes to (3) are unlimited in nature, (2) is a discrete number so it can have some upper bound (I was thinking more on PCs in this last statement).
Sure, I can optimize for both performance & memory usage by
always reusing allocations done by previously-
clear'ed
vector's. It will add some bits to the code. Shall I do that? Or did you have other things in mind?