Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix texture data race #1202

Merged
merged 2 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions core/src/text/fontContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ void FontContext::releaseAtlas(std::bitset<max_textures> _refs) {
if (!_refs.any()) { return; }
std::lock_guard<std::mutex> lock(m_textureMutex);
for (size_t i = 0; i < m_textures.size(); i++) {
if (!_refs[i]) { continue; }

if (--m_atlasRefCount[i] == 0) {
LOGD("CLEAR ATLAS %d", i);
m_atlas.clear(i);
m_textures[i].texData.assign(GlyphTexture::size * GlyphTexture::size, 0);
}
if (_refs[i]) { m_atlasRefCount[i] -= 1; }
}
}

Expand Down Expand Up @@ -216,18 +210,29 @@ bool FontContext::layoutText(TextStyle::Parameters& _params, const std::string&
glm::vec2 offset((metrics.aabb.x + width * 0.5) * TextVertex::position_scale,
(metrics.aabb.y + height * 0.5) * TextVertex::position_scale);

{
std::lock_guard<std::mutex> lock(m_textureMutex);
for (; it != _quads.end(); ++it) {

for (; it != _quads.end(); ++it) {
if (!_refs[it->atlas]) {
_refs[it->atlas] = true;
m_atlasRefCount[it->atlas]++;
}

if (!_refs[it->atlas]) {
_refs[it->atlas] = true;
m_atlasRefCount[it->atlas]++;
it->quad[0].pos -= offset;
it->quad[1].pos -= offset;
it->quad[2].pos -= offset;
it->quad[3].pos -= offset;
}

it->quad[0].pos -= offset;
it->quad[1].pos -= offset;
it->quad[2].pos -= offset;
it->quad[3].pos -= offset;
// Clear unused textures
for (size_t i = 0; i < m_textures.size(); i++) {
if (m_atlasRefCount[i] == 0) {
m_atlas.clear(i);
m_textures[i].texData.assign(GlyphTexture::size *
GlyphTexture::size, 0);
}
}
}

return true;
Expand Down
2 changes: 0 additions & 2 deletions core/src/text/fontContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ class FontContext : public alfons::TextureCallback {

void releaseAtlas(std::bitset<max_textures> _refs);

alfons::GlyphAtlas& atlas() { return m_atlas; }

/* Update all textures batches, uploads the data to the GPU */
void updateTextures(RenderState& rs);

Expand Down