mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-27 05:26:13 +01:00
use unique_ptr to handle memory of sfTexture
This commit is contained in:
1 parent
3826091357
commit
082a90ec4f
2 files changed
+9
-8
No files matched your search
@@ -53,18 +53,17 @@ sfRenderTexture* sfRenderTexture_create(sfVector2u size, const sfContextSettings
|
|||||||
if (!renderTexture.resize(convertVector2(size), params))
|
if (!renderTexture.resize(convertVector2(size), params))
|
||||||
return nullptr;
|
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 defaultView = sfView{renderTexture.getDefaultView()};
|
||||||
const auto currentView = sfView{renderTexture.getView()};
|
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)
|
void sfRenderTexture_destroy(const sfRenderTexture* renderTexture)
|
||||||
{
|
{
|
||||||
delete renderTexture->Target;
|
|
||||||
delete renderTexture;
|
delete renderTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +274,7 @@ void sfRenderTexture_resetGLStates(sfRenderTexture* renderTexture)
|
|||||||
const sfTexture* sfRenderTexture_getTexture(const sfRenderTexture* renderTexture)
|
const sfTexture* sfRenderTexture_getTexture(const sfRenderTexture* renderTexture)
|
||||||
{
|
{
|
||||||
assert(renderTexture);
|
assert(renderTexture);
|
||||||
return renderTexture->Target;
|
return renderTexture->Target.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,14 +32,16 @@
|
|||||||
|
|
||||||
#include <SFML/Graphics/RenderTexture.hpp>
|
#include <SFML/Graphics/RenderTexture.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Internal structure of sfRenderTexture
|
// Internal structure of sfRenderTexture
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct sfRenderTexture
|
struct sfRenderTexture
|
||||||
{
|
{
|
||||||
sf::RenderTexture This;
|
sf::RenderTexture This;
|
||||||
const sfTexture* Target;
|
std::unique_ptr<const sfTexture> Target;
|
||||||
sfView DefaultView;
|
sfView DefaultView;
|
||||||
sfView CurrentView;
|
sfView CurrentView;
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user