[client,sdl] keep SDL_RWops open
the application crashes if we close the SDL_RWops after opening the font. keep it open until the widget is destroyed
This commit is contained in:
parent
33c1183fe1
commit
c7b123076a
@ -42,21 +42,23 @@ SdlWidget::SdlWidget(SDL_Renderer* renderer, const SDL_Rect& rect, bool input)
|
||||
{
|
||||
assert(renderer);
|
||||
|
||||
auto ops = SDL_RWFromConstMem(font_buffer.data(), static_cast<int>(font_buffer.size()));
|
||||
if (ops)
|
||||
_font = TTF_OpenFontRW(ops, 0, 64);
|
||||
SDL_RWclose(ops);
|
||||
_ops = SDL_RWFromConstMem(font_buffer.data(), static_cast<int>(font_buffer.size()));
|
||||
if (_ops)
|
||||
_font = TTF_OpenFontRW(_ops, 0, 64);
|
||||
}
|
||||
|
||||
SdlWidget::SdlWidget(SdlWidget&& other) noexcept
|
||||
: _font(std::move(other._font)), _rect(std::move(other._rect))
|
||||
: _font(std::move(other._font)), _ops(other._ops), _rect(std::move(other._rect))
|
||||
{
|
||||
other._font = nullptr;
|
||||
other._ops = nullptr;
|
||||
}
|
||||
|
||||
SdlWidget::~SdlWidget()
|
||||
{
|
||||
TTF_CloseFont(_font);
|
||||
if (_ops)
|
||||
SDL_RWclose(_ops);
|
||||
}
|
||||
|
||||
bool SdlWidget::error_ex(Uint32 res, const char* what, const char* file, size_t line,
|
||||
|
@ -72,6 +72,7 @@ class SdlWidget
|
||||
|
||||
private:
|
||||
TTF_Font* _font;
|
||||
SDL_RWops* _ops;
|
||||
SDL_Rect _rect;
|
||||
bool _input;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user