use unique_ptr to handle memory of sfTexture

This commit is contained in:
ZXShady authored and Chris Thrasher committed 2024-09-18 10:52:21 -04:00
1 parent 3826091357
commit 082a90ec4f
2 files changed
+9 -8

No files matched your search

+3 -4
View File
@@ -53,18 +53,17 @@ sfRenderTexture* sfRenderTexture_create(sfVector2u size, const sfContextSettings
if (!renderTexture.resize(convertVector2(size), params))
return nullptr;
auto* texture = new sfTexture(const_cast<sf::Texture*>(&renderTexture.getTexture()));
auto texture = std::make_unique<sfTexture>(const_cast<sf::Texture*>(&renderTexture.getTexture()));
const auto defaultView = sfView{renderTexture.getDefaultView()};
const auto currentView = sfView{renderTexture.getView()};
return new sfRenderTexture{std::move(renderTexture), texture, defaultView, currentView};
return new sfRenderTexture{std::move(renderTexture), std::move(texture), defaultView, currentView};
}
////////////////////////////////////////////////////////////
void sfRenderTexture_destroy(const sfRenderTexture* renderTexture)
{
delete renderTexture->Target;
delete renderTexture;
}
@@ -275,7 +274,7 @@ void sfRenderTexture_resetGLStates(sfRenderTexture* renderTexture)
const sfTexture* sfRenderTexture_getTexture(const sfRenderTexture* renderTexture)
{
assert(renderTexture);
return renderTexture->Target;
return renderTexture->Target.get();
}
+6 -4
View File
@@ -32,14 +32,16 @@
#include <SFML/Graphics/RenderTexture.hpp>
#include <memory>
////////////////////////////////////////////////////////////
// Internal structure of sfRenderTexture
////////////////////////////////////////////////////////////
struct sfRenderTexture
{
sf::RenderTexture This;
const sfTexture* Target;
sfView DefaultView;
sfView CurrentView;
sf::RenderTexture This;
std::unique_ptr<const sfTexture> Target;
sfView DefaultView;
sfView CurrentView;
};