From 66540ff86f59039770476fdfd42c4d543b893bb7 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 3 Jun 2019 21:56:53 -0400 Subject: [PATCH] Permits end_data only after a begin_data. --- Outputs/OpenGL/ScanTarget.cpp | 8 ++++++-- Outputs/OpenGL/ScanTarget.hpp | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Outputs/OpenGL/ScanTarget.cpp b/Outputs/OpenGL/ScanTarget.cpp index be44733a6..08e1d4fbc 100644 --- a/Outputs/OpenGL/ScanTarget.cpp +++ b/Outputs/OpenGL/ScanTarget.cpp @@ -208,7 +208,8 @@ uint8_t *ScanTarget::begin_data(size_t required_length, size_t required_alignmen 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); 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) { - 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. 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 - 2) * data_type_size_], data_type_size_); + + // Record that no further end_data calls are expected. + data_is_allocated_ = false; } void ScanTarget::will_change_owner() { diff --git a/Outputs/OpenGL/ScanTarget.hpp b/Outputs/OpenGL/ScanTarget.hpp index 5a5dde05e..ce7d671a7 100644 --- a/Outputs/OpenGL/ScanTarget.hpp +++ b/Outputs/OpenGL/ScanTarget.hpp @@ -186,6 +186,7 @@ class ScanTarget: public Outputs::Display::ScanTarget { int vended_write_area_pointer_ = 0; // Track allocation failures. + bool data_is_allocated_ = false; bool allocation_has_failed_ = false; bool line_allocation_has_failed_ = false;