1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 18:30:21 +00:00

Added an extra flag to avoid potential race condition on is_full_, being reset from the background despite a write area not having been allocated.

This commit is contained in:
Thomas Harte 2017-01-29 16:11:29 -05:00
parent acadfbabec
commit 427175b9c0
2 changed files with 5 additions and 1 deletions

View File

@ -43,6 +43,7 @@ TextureBuilder::TextureBuilder(size_t bytes_per_pixel, GLenum texture_unit) :
write_areas_start_y_(0),
is_full_(false),
did_submit_(false),
has_write_area_(false),
number_of_write_areas_(0)
{
image_.resize(bytes_per_pixel * InputBufferBuilderWidth * InputBufferBuilderHeight);
@ -105,6 +106,7 @@ uint8_t *TextureBuilder::allocate_write_area(size_t required_length)
else
write_areas_.push_back(next_write_area);
number_of_write_areas_++;
has_write_area_ = true;
return pointer_to_location(next_write_area.x, next_write_area.y);
}
@ -116,8 +118,9 @@ bool TextureBuilder::is_full()
void TextureBuilder::reduce_previous_allocation_to(size_t actual_length)
{
if(is_full_) return;
if(is_full_ || !has_write_area_) return;
has_write_area_ = false;
WriteArea &write_area = write_areas_[number_of_write_areas_-1];
write_area.length = (uint16_t)actual_length;

View File

@ -69,6 +69,7 @@ class TextureBuilder {
size_t number_of_write_areas_;
bool is_full_;
bool did_submit_;
bool has_write_area_;
inline uint8_t *pointer_to_location(uint16_t x, uint16_t y);
// Usually: the start position for the current batch of write areas.