From: Steinar H. Gunderson Date: Tue, 12 May 2020 20:09:24 +0000 (+0200) Subject: Fix behavior around reconfigure. X-Git-Tag: 2.0.0~35 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=0478d360a9aa0f816b21b0c6b1df91c1426c35d6;hp=11d27b16a092efb99c045b21903da0eb7ee8c4d1 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. --- 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);