1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00

Merge pull request #624 from TomHarte/BookendCrash

Permits end_data only after a begin_data.
This commit is contained in:
Thomas Harte 2019-06-03 21:57:59 -04:00 committed by GitHub
commit 299a7b99ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -208,7 +208,8 @@ uint8_t *ScanTarget::begin_data(size_t required_length, size_t required_alignmen
return nullptr; return nullptr;
} }
// Everything checks out, return the pointer. // Everything checks out, note expectation of a future end_data and return the pointer.
data_is_allocated_ = true;
vended_write_area_pointer_ = write_pointers_.write_area = TextureAddress(aligned_start_x, output_y); vended_write_area_pointer_ = write_pointers_.write_area = TextureAddress(aligned_start_x, output_y);
return &write_area_texture_[size_t(write_pointers_.write_area) * data_type_size_]; return &write_area_texture_[size_t(write_pointers_.write_area) * data_type_size_];
@ -217,7 +218,7 @@ uint8_t *ScanTarget::begin_data(size_t required_length, size_t required_alignmen
} }
void ScanTarget::end_data(size_t actual_length) { void ScanTarget::end_data(size_t actual_length) {
if(allocation_has_failed_) return; if(allocation_has_failed_ || !data_is_allocated_) return;
// Bookend the start of the new data, to safeguard for precision errors in sampling. // Bookend the start of the new data, to safeguard for precision errors in sampling.
memcpy( memcpy(
@ -234,6 +235,9 @@ void ScanTarget::end_data(size_t actual_length) {
&write_area_texture_[size_t(write_pointers_.write_area - 1) * data_type_size_], &write_area_texture_[size_t(write_pointers_.write_area - 1) * data_type_size_],
&write_area_texture_[size_t(write_pointers_.write_area - 2) * data_type_size_], &write_area_texture_[size_t(write_pointers_.write_area - 2) * data_type_size_],
data_type_size_); data_type_size_);
// Record that no further end_data calls are expected.
data_is_allocated_ = false;
} }
void ScanTarget::will_change_owner() { void ScanTarget::will_change_owner() {

View File

@ -186,6 +186,7 @@ class ScanTarget: public Outputs::Display::ScanTarget {
int vended_write_area_pointer_ = 0; int vended_write_area_pointer_ = 0;
// Track allocation failures. // Track allocation failures.
bool data_is_allocated_ = false;
bool allocation_has_failed_ = false; bool allocation_has_failed_ = false;
bool line_allocation_has_failed_ = false; bool line_allocation_has_failed_ = false;