Skip to content

Commit

Permalink
squash synchronize FontContext m_atlasRefs
Browse files Browse the repository at this point in the history
- don't clear textures directly in releaseAtlas. This could clear the
  atlas while it's used in layoutText, before the atlas ref count got
  updated.
  • Loading branch information
hjanetzek committed Dec 26, 2016
1 parent 4f64a90 commit a72d4c5
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 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,7 +210,6 @@ 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) {
Expand All @@ -231,6 +224,15 @@ bool FontContext::layoutText(TextStyle::Parameters& _params, const std::string&
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

0 comments on commit a72d4c5

Please sign in to comment.