Skip to content

Commit 9dadc7b

Browse files
committed
Fixing a bad reference capture and null checking before we do risky things in the initial rener manager
1 parent e4c6278 commit 9dadc7b

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

src/include/server/mir/graphics/default_initial_render_manager.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ class DefaultInitialRenderManager : public InitialRenderManager
4545
public:
4646
DefaultInitialRenderManager(
4747
std::shared_ptr<Executor> const& scene_executor,
48-
std::shared_ptr<time::Clock>& clock,
48+
std::shared_ptr<time::Clock> const& clock,
4949
time::AlarmFactory& alarm_factory,
50-
std::shared_ptr<input::Scene>& scene);
50+
std::shared_ptr<input::Scene> const& scene);
5151
~DefaultInitialRenderManager();
5252
void add_initial_render(std::shared_ptr<InitialRender> const&) override;
5353

5454
private:
5555
void remove_renderables();
56-
std::shared_ptr<Executor> const& scene_executor;
57-
std::shared_ptr<time::Clock> const& clock;
58-
std::shared_ptr<input::Scene>& scene;
56+
std::shared_ptr<Executor> const scene_executor;
57+
std::shared_ptr<time::Clock> const clock;
58+
std::shared_ptr<input::Scene> const scene;
5959
std::vector<std::shared_ptr<Renderable>> renderable_list;
6060
std::unique_ptr<time::Alarm> const alarm;
6161
};

src/server/graphics/default_configuration.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ mir::DefaultServerConfiguration::the_initial_render_manager(mg::Display& in_disp
508508
auto in_main_loop = the_main_loop();
509509
auto in_clock = the_clock();
510510
initial_render_manager = std::make_shared<mg::DefaultInitialRenderManager>(
511-
the_main_loop(),
511+
in_main_loop,
512512
in_clock,
513513
*in_main_loop,
514514
in_input_scene);

src/server/graphics/default_initial_render_manager.cpp

+26-13
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
#include "mir/time/alarm_factory.h"
2020
#include "mir/time/clock.h"
2121
#include "mir/executor.h"
22+
#include "mir/log.h"
2223
#include <chrono>
2324

2425
namespace mg = mir::graphics;
2526

2627
mg::DefaultInitialRenderManager::DefaultInitialRenderManager(
2728
std::shared_ptr<Executor> const& scene_executor,
28-
std::shared_ptr<time::Clock>&clock,
29-
time::AlarmFactory &alarm_factory,
30-
std::shared_ptr<input::Scene>& scene)
29+
std::shared_ptr<time::Clock> const& clock,
30+
time::AlarmFactory& alarm_factory,
31+
std::shared_ptr<input::Scene> const& scene)
3132
: scene_executor{scene_executor},
3233
clock{clock},
3334
scene{scene},
@@ -49,24 +50,36 @@ void mg::DefaultInitialRenderManager::add_initial_render(std::shared_ptr<Initial
4950
if (!initial_render)
5051
return;
5152

53+
if (!scene)
54+
{
55+
mir::log_error("Unable to add the initial renderables because the scene does not exist");
56+
return;
57+
}
58+
5259
for (auto const& renderable : initial_render->get_renderables())
5360
{
54-
scene_executor->spawn([scene = scene, to_add = renderable]()
55-
{
56-
scene->add_input_visualization(to_add);
57-
});
61+
scene->add_input_visualization(renderable);
5862
renderable_list.push_back(renderable);
5963
}
6064
}
6165

6266
void mg::DefaultInitialRenderManager::remove_renderables()
6367
{
64-
for (auto const& renderable : renderable_list)
68+
if (!scene_executor)
6569
{
66-
scene_executor->spawn([scene = scene, to_remove = renderable]()
67-
{
68-
scene->remove_input_visualization(to_remove);
69-
});
70+
mir::log_error("Unable to remove the initial renderables because the executor does not exist");
71+
return;
7072
}
71-
renderable_list.clear();
73+
74+
if (!scene)
75+
{
76+
mir::log_error("Unable to remove the initial renerables because the scene does not exist");
77+
return;
78+
}
79+
80+
scene_executor->spawn([the_scene = scene, to_remove = renderable_list]()
81+
{
82+
for (auto const& renderable : to_remove)
83+
the_scene->remove_input_visualization(renderable);
84+
});
7285
}

0 commit comments

Comments
 (0)