Switched UIFrame and Scene to store their UIDrawables in shared_ptr to vector, instead of directly to vector. Every object that can be exposed to Python has to be safely shareable so it doesn't become a segfault, and that includes the UIDrawable collections AND the UIDrawable members. So we get the terrifying type for collections of child elements: 'std::shared_ptr<std::vector<std::shared_ptr<UIDrawable>>>'. May I be forgiven for my sins

This commit is contained in:
John McCardle 2023-09-02 14:00:48 -04:00
commit 0ef0a5d506
7 changed files with 32 additions and 15 deletions

View file

@ -10,6 +10,7 @@ void UIDrawable::render()
UIFrame::UIFrame():
x(0), y(0), w(0), h(0), outline(0)
{
children = std::make_shared<std::vector<std::shared_ptr<UIDrawable>>>();
/*
pyOutlineColor = NULL;
pyFillColor = NULL;
@ -21,6 +22,7 @@ x(0), y(0), w(0), h(0), outline(0)
UIFrame::UIFrame(float _x, float _y, float _w, float _h):
x(_x), y(_y), w(_w), h(_h), outline(0)
{
children = std::make_shared<std::vector<std::shared_ptr<UIDrawable>>>();
/*
pyOutlineColor = NULL;
pyFillColor = NULL;
@ -31,6 +33,7 @@ x(_x), y(_y), w(_w), h(_h), outline(0)
UIFrame::~UIFrame()
{
children.reset();
/*
if (pyOutlineColor) Py_DECREF(pyOutlineColor);
else if (_outlineColor) delete _outlineColor;
@ -64,7 +67,7 @@ void UIFrame::render(sf::Vector2f offset)
//if (_outlineColor) { box.setOutlineColor(outlineColor()); }
//box.setOutlineThickness(outline);
//Resources::game->getWindow().draw(box);
for (auto drawable : children) {
for (auto drawable : *children) {
drawable->render(offset + box.getPosition());
}
}