Skip to content

Commit c5ff2f0

Browse files
committed
context checking
1 parent d9985e6 commit c5ff2f0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/ruis/gui.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ void gui::set_root(utki::shared_ref<ruis::widget> w)
113113
throw std::invalid_argument("given widget is already added to some container");
114114
}
115115

116+
if (w.get().context.to_shared_ptr() != this->context.to_shared_ptr()) {
117+
throw std::invalid_argument("cannot set root widget from another GUI context");
118+
}
119+
116120
this->root_widget = std::move(w);
117121

118122
this->root_widget.get().move_to(ruis::vector2(0));

src/ruis/widget/container.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ widget_list::const_iterator container::insert_internal(
270270
throw std::invalid_argument("container::insert(): the widget is already added to some other container");
271271
}
272272

273+
if (ww.context.to_shared_ptr() != this->context.to_shared_ptr()) {
274+
throw std::invalid_argument("container::insert(): cannot insert widget from another GUI context");
275+
}
276+
273277
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
274278
auto ret = this->children_list.variable.emplace(
275279
before, //

0 commit comments

Comments
 (0)