Skip to content

Commit d6a6974

Browse files
committed
Update to latest changes
1 parent 4727cf1 commit d6a6974

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

imgui-SFML.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ struct WindowContext {
172172
const sf::Window* window;
173173
ImGuiContext* imContext{ImGui::CreateContext()};
174174

175-
sf::Texture fontTexture; // internal font atlas which is used if user doesn't set a custom
176-
// sf::Texture.
175+
std::optional<sf::Texture> fontTexture; // internal font atlas which is used if user doesn't set
176+
// a custom sf::Texture.
177177

178178
bool windowHasFocus;
179179
bool mouseMoved{false};
@@ -499,20 +499,24 @@ bool UpdateFontTexture() {
499499

500500
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
501501

502-
sf::Texture& texture = s_currWindowCtx->fontTexture;
503-
if (!texture.create({static_cast<unsigned>(width), static_cast<unsigned>(height)})) {
502+
auto newTexture =
503+
sf::Texture::create({static_cast<unsigned>(width), static_cast<unsigned>(height)});
504+
505+
if (!newTexture.has_value()) {
504506
return false;
505507
}
506508

507-
texture.update(pixels);
509+
newTexture->update(pixels);
508510

509-
ImTextureID texID = convertGLTextureHandleToImTextureID(texture.getNativeHandle());
511+
ImTextureID texID = convertGLTextureHandleToImTextureID(newTexture->getNativeHandle());
510512
io.Fonts->SetTexID(texID);
511513

514+
s_currWindowCtx->fontTexture = std::move(newTexture);
515+
512516
return true;
513517
}
514518

515-
sf::Texture& GetFontTexture() {
519+
std::optional<sf::Texture>& GetFontTexture() {
516520
assert(s_currWindowCtx);
517521
return s_currWindowCtx->fontTexture;
518522
}

imgui-SFML.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <SFML/System/Vector2.hpp>
88
#include <SFML/Window/Joystick.hpp>
99

10+
#include <optional>
11+
1012
#include "imgui-SFML_export.h"
1113

1214
namespace sf {
@@ -44,7 +46,7 @@ IMGUI_SFML_API void Shutdown(const sf::Window& window);
4446
IMGUI_SFML_API void Shutdown();
4547

4648
[[nodiscard]] IMGUI_SFML_API bool UpdateFontTexture();
47-
IMGUI_SFML_API sf::Texture& GetFontTexture();
49+
IMGUI_SFML_API std::optional<sf::Texture>& GetFontTexture();
4850

4951
// joystick functions
5052
IMGUI_SFML_API void SetActiveJoystickId(unsigned int joystickId);

0 commit comments

Comments
 (0)