Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - theo

Pages: [1]
1
SFML development / move semantics for sf::context
« on: October 29, 2023, 03:25:21 pm »
Hello,
I'm willing to help out on this one, and in principle it's not hard, this object contains just one unique_ptr, so move constructor and move assignment can be defaulted.
Of course there is a complication. In the moved-from object, the m_context pointer will be nullptr. Fixing the destructor is not too hard: just do nothing if m_context is nullptr (the moved-to instance is owner now):

Context::~Context()
{
    if (m_context)
    {
        if (m_context) // if moved from, m_context will be nullptr. In that case, do nothing.
        {
            if (!setActive(false))
            {
                err() << "Failed to set context as inactive during destruction" << std::endl;
            }
        }
    }
}


But the other two member functions, setActive and getSettings also access this pointer, that is nullptr in the case it is moved from.

My questions:
- is it acceptable to you to just have undefined behaviour (a crash) if setActive and/or getSettings are called on a moved-from instance of sf::Context?

if not:
- for setActive, is it acceptable to just return false on a call on a moved-from instance? Of course, in this case the destructor still has to be altered, otherwise it wil cause the diagnostic every time a moved-from sf::Context object runs out of scope.
- for getSettings, is it acceptable to return a default-constructed ContextSettings on a call on a moved-from instance?

2
Graphics / problem with sf::Text getGlobalBounds() / getLocalBounds()
« on: September 15, 2021, 02:35:43 pm »
I take the bounds of an sf::Text object:

sf::Text t{};
t.setFont(m_font);  // yes, m_font is loaded and in scope at this point
t.setString("Hello world");
t.setCharacterSize(20);
auto bounds = t.getGlobalBounds();  // same behaviour with getLocalBounds()

This used to work fine, but now I get the following error:

Exception thrown at 0x00007FFCCAAD2B8D (freetyped.dll) in test.exe: 0xC0000005: Access violation reading location 0x0000000000000008.

The only thing that seems to have changed is an upgrade of freetype to version 2.11.0 (through vcpkg). This might be more a bug in freetype than in SFML, but I can't really tell.

Pages: [1]