From 0478d360a9aa0f816b21b0c6b1df91c1426c35d6 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 12 May 2020 22:09:24 +0200 Subject: [PATCH] Fix behavior around reconfigure. When disconnecting a fake card and replacing it with an SRT card (or, theoretically, vice versa), we'd delete the old frames assuming the old pixel format, which would cause us to delete garbage data and eventually (seemingly?) use deleted texture numbers, causing GL errors and thus crashes. --- nageru/pbo_frame_allocator.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/nageru/pbo_frame_allocator.cpp b/nageru/pbo_frame_allocator.cpp index 70675b1..1000a72 100644 --- a/nageru/pbo_frame_allocator.cpp +++ b/nageru/pbo_frame_allocator.cpp @@ -437,7 +437,15 @@ void PBOFrameAllocator::reconfigure(bmusb::PixelFormat pixel_format, return; } - size_t old_num_queued_frames = this->num_queued_frames; + lock_guard lock(freelist_mutex); + lingering_generations[generation] = LingeringGeneration{ move(userdata), this->num_queued_frames }; + ++generation; + + while (!freelist.empty()) { + Frame frame = freelist.front(); + freelist.pop(); + destroy_frame(&frame); + } this->pixel_format = pixel_format; this->frame_size = frame_size; @@ -450,16 +458,6 @@ void PBOFrameAllocator::reconfigure(bmusb::PixelFormat pixel_format, this->permissions = permissions; this->map_bits = map_bits; - lock_guard lock(freelist_mutex); - lingering_generations[generation] = LingeringGeneration{ move(userdata), old_num_queued_frames }; - ++generation; - - while (!freelist.empty()) { - Frame frame = freelist.front(); - freelist.pop(); - destroy_frame(&frame); - } - userdata.reset(new Userdata[num_queued_frames]); for (size_t i = 0; i < num_queued_frames; ++i) { init_frame(i, frame_size, width, height, permissions, map_bits, generation); -- 2.39.2