]> git.sesse.net Git - nageru/commitdiff
Fix behavior around reconfigure.
authorSteinar H. Gunderson <steinar+nageru@gunderson.no>
Tue, 12 May 2020 20:09:24 +0000 (22:09 +0200)
committerSteinar H. Gunderson <steinar+nageru@gunderson.no>
Tue, 12 May 2020 20:10:49 +0000 (22:10 +0200)
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

index 70675b1a630dfbdf1c30730f5134e9f014820c41..1000a727326604c2d30a2f7567b296f0af096833 100644 (file)
@@ -437,7 +437,15 @@ void PBOFrameAllocator::reconfigure(bmusb::PixelFormat pixel_format,
                return;
        }
 
-       size_t old_num_queued_frames = this->num_queued_frames;
+       lock_guard<mutex> 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<mutex> 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);