Hmm, actually SurfaceSnapshot doesn't really need the BufferStream at all. The SurfaceSnapshot is created at the instance when we want to composite. We should instead just pass it a buffer, and not let it hold a reference to the BufferStream. In theory that should guarantee that BasicSurface holds a unique pointer (which we should enforce as unique_ptr) to BufferStream and thus it would become impossible for the BufferQueue to live longer than the surface it calls back into.
I think that would be a nicer (and smaller?) fix, if it works.
Hmm, actually SurfaceSnapshot doesn't really need the BufferStream at all. The SurfaceSnapshot is created at the instance when we want to composite. We should instead just pass it a buffer, and not let it hold a reference to the BufferStream. In theory that should guarantee that BasicSurface holds a unique pointer (which we should enforce as unique_ptr) to BufferStream and thus it would become impossible for the BufferQueue to live longer than the surface it calls back into.
I think that would be a nicer (and smaller?) fix, if it works.