Skip to content

Commit

Permalink
Merge #1277
Browse files Browse the repository at this point in the history
1277: BasicSurface: clear all frame posted callbacks in the destructor r=AlanGriffiths a=wmww

See discussion in #1273. This prevents observers being sent pointers to dead surfaces.

Co-authored-by: William Wold <[email protected]>
  • Loading branch information
2 people authored and AlanGriffiths committed Feb 17, 2020
1 parent 12b4ad1 commit 56a8bd8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/server/scene/basic_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ ms::BasicSurface::BasicSurface(

ms::BasicSurface::~BasicSurface() noexcept
{
for(auto& layer : layers)
layer.stream->set_frame_posted_callback([](auto){});
report->surface_deleted(this, surface_name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ TEST_F(SurfaceStackCompositor, compositor_runs_until_all_surfaces_buffers_are_co
ON_CALL(*mock_buffer_stream, buffers_ready_for_compositor(_))
.WillByDefault(Return(5));
EXPECT_CALL(*mock_buffer_stream, set_frame_posted_callback(_))
.WillOnce(SaveArg<0>(&frame_callback));
.WillOnce(SaveArg<0>(&frame_callback))
.WillRepeatedly(Return());
stub_surface->set_streams(std::list<ms::StreamInfo>{ { mock_buffer_stream, {0,0}, geom::Size{100, 100} } });

mc::MultiThreadedCompositor mt_compositor(
Expand All @@ -242,7 +243,8 @@ TEST_F(SurfaceStackCompositor, bypassed_compositor_runs_until_all_surfaces_buffe
ON_CALL(*mock_buffer_stream, lock_compositor_buffer(_))
.WillByDefault(Return(mt::fake_shared(*stub_buffer)));
EXPECT_CALL(*mock_buffer_stream, set_frame_posted_callback(_))
.WillOnce(SaveArg<0>(&frame_callback));
.WillOnce(SaveArg<0>(&frame_callback))
.WillRepeatedly(Return());
stub_surface->set_streams(std::list<ms::StreamInfo>{ { mock_buffer_stream, {0,0}, geom::Size{100, 100} } });

stub_surface->resize(geom::Size{10,10});
Expand Down
12 changes: 8 additions & 4 deletions tests/unit-tests/scene/test_basic_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,10 @@ TEST_F(BasicSurfaceTest, registers_frame_callbacks_on_construction)
{ buffer_stream1, {0,0}, {} }
};

EXPECT_CALL(*buffer_stream0, set_frame_posted_callback(_));
EXPECT_CALL(*buffer_stream1, set_frame_posted_callback(_));
EXPECT_CALL(*buffer_stream0, set_frame_posted_callback(_))
.Times(AtLeast(1));
EXPECT_CALL(*buffer_stream1, set_frame_posted_callback(_))
.Times(AtLeast(1));

ms::BasicSurface child{
nullptr /* session */,
Expand All @@ -1344,8 +1346,10 @@ TEST_F(BasicSurfaceTest, registers_frame_callbacks_on_set_streams)
{ buffer_stream1, {0,0}, {} }
};

EXPECT_CALL(*buffer_stream0, set_frame_posted_callback(_));
EXPECT_CALL(*buffer_stream1, set_frame_posted_callback(_));
EXPECT_CALL(*buffer_stream0, set_frame_posted_callback(_))
.Times(AtLeast(1));
EXPECT_CALL(*buffer_stream1, set_frame_posted_callback(_))
.Times(AtLeast(1));

surface.set_streams(streams);
}
Expand Down

0 comments on commit 56a8bd8

Please sign in to comment.