mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-27 05:26:13 +01:00
Remove all delete calls outside of _destroy functions
This commit is contained in:
1 parent
ac477cf8b2
commit
5b910f8761
6 files changed
+64
-125
No files matched your search
+11
-21
@@ -35,28 +35,22 @@ sfMusic* sfMusic_createFromFile(const char* filename)
|
|||||||
{
|
{
|
||||||
assert(filename);
|
assert(filename);
|
||||||
|
|
||||||
auto* music = new sfMusic;
|
sf::Music music;
|
||||||
if (!music->This.openFromFile(filename))
|
if (!music.openFromFile(filename))
|
||||||
{
|
return nullptr;
|
||||||
delete music;
|
|
||||||
music = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return music;
|
return new sfMusic{std::move(music), {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfMusic* sfMusic_createFromMemory(const void* data, size_t sizeInBytes)
|
sfMusic* sfMusic_createFromMemory(const void* data, size_t sizeInBytes)
|
||||||
{
|
{
|
||||||
auto* music = new sfMusic;
|
sf::Music music;
|
||||||
if (!music->This.openFromMemory(data, sizeInBytes))
|
if (!music.openFromMemory(data, sizeInBytes))
|
||||||
{
|
return nullptr;
|
||||||
delete music;
|
|
||||||
music = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return music;
|
return new sfMusic{std::move(music), {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,15 +59,11 @@ sfMusic* sfMusic_createFromStream(sfInputStream* stream)
|
|||||||
{
|
{
|
||||||
assert(stream);
|
assert(stream);
|
||||||
|
|
||||||
auto* music = new sfMusic;
|
auto music = std::make_unique<sfMusic>(sfMusic{{}, {stream}});
|
||||||
music->Stream = CallbackStream(stream);
|
|
||||||
if (!music->This.openFromStream(music->Stream))
|
if (!music->This.openFromStream(music->Stream))
|
||||||
{
|
return nullptr;
|
||||||
delete music;
|
|
||||||
music = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return music;
|
return music.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,6 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct sfMusic
|
struct sfMusic
|
||||||
{
|
{
|
||||||
CallbackStream Stream;
|
|
||||||
sf::Music This;
|
sf::Music This;
|
||||||
|
CallbackStream Stream;
|
||||||
};
|
};
|
||||||
@@ -60,15 +60,11 @@ sfFont* sfFont_createFromStream(sfInputStream* stream)
|
|||||||
{
|
{
|
||||||
assert(stream);
|
assert(stream);
|
||||||
|
|
||||||
auto* font = new sfFont;
|
auto font = std::make_unique<sfFont>(sfFont{{}, {}, {stream}});
|
||||||
font->Stream = CallbackStream(stream);
|
|
||||||
if (!font->This.openFromStream(font->Stream))
|
if (!font->This.openFromStream(font->Stream))
|
||||||
{
|
return nullptr;
|
||||||
delete font;
|
|
||||||
font = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return font;
|
return font.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,19 +34,17 @@
|
|||||||
#include <CSFML/System/ConvertVector2.hpp>
|
#include <CSFML/System/ConvertVector2.hpp>
|
||||||
#include <CSFML/Window/WindowStruct.hpp>
|
#include <CSFML/Window/WindowStruct.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTexture* sfTexture_create(sfVector2u size)
|
sfTexture* sfTexture_create(sfVector2u size)
|
||||||
{
|
{
|
||||||
auto* texture = new sfTexture;
|
auto texture = std::make_unique<sfTexture>();
|
||||||
|
|
||||||
if (!texture->This->resize(convertVector2(size)))
|
if (!texture->This->resize(convertVector2(size)))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -55,17 +53,12 @@ sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area)
|
|||||||
{
|
{
|
||||||
assert(filename);
|
assert(filename);
|
||||||
|
|
||||||
auto* texture = new sfTexture;
|
const auto rect = area ? convertRect(*area) : sf::IntRect();
|
||||||
|
auto texture = std::make_unique<sfTexture>();
|
||||||
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
|
|
||||||
|
|
||||||
if (!texture->This->loadFromFile(filename, false, rect))
|
if (!texture->This->loadFromFile(filename, false, rect))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@@ -73,49 +66,34 @@ sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* a
|
|||||||
{
|
{
|
||||||
assert(filename);
|
assert(filename);
|
||||||
|
|
||||||
auto* texture = new sfTexture;
|
const auto rect = area ? convertRect(*area) : sf::IntRect();
|
||||||
|
auto texture = std::make_unique<sfTexture>();
|
||||||
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
|
|
||||||
|
|
||||||
if (!texture->This->loadFromFile(filename, true, rect))
|
if (!texture->This->loadFromFile(filename, true, rect))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
|
sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
|
||||||
{
|
{
|
||||||
auto* texture = new sfTexture;
|
const auto rect = area ? convertRect(*area) : sf::IntRect();
|
||||||
|
auto texture = std::make_unique<sfTexture>();
|
||||||
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
|
|
||||||
|
|
||||||
if (!texture->This->loadFromMemory(data, sizeInBytes, false, rect))
|
if (!texture->This->loadFromMemory(data, sizeInBytes, false, rect))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTexture* sfTexture_createSrgbFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
|
sfTexture* sfTexture_createSrgbFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
|
||||||
{
|
{
|
||||||
auto* texture = new sfTexture;
|
const auto rect = area ? convertRect(*area) : sf::IntRect();
|
||||||
|
auto texture = std::make_unique<sfTexture>();
|
||||||
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
|
|
||||||
|
|
||||||
if (!texture->This->loadFromMemory(data, sizeInBytes, true, rect))
|
if (!texture->This->loadFromMemory(data, sizeInBytes, true, rect))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -124,18 +102,13 @@ sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* ar
|
|||||||
{
|
{
|
||||||
assert(stream);
|
assert(stream);
|
||||||
|
|
||||||
auto* texture = new sfTexture;
|
const auto rect = area ? convertRect(*area) : sf::IntRect();
|
||||||
|
|
||||||
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
|
|
||||||
|
|
||||||
CallbackStream sfmlStream(stream);
|
CallbackStream sfmlStream(stream);
|
||||||
|
auto texture = std::make_unique<sfTexture>();
|
||||||
if (!texture->This->loadFromStream(sfmlStream, false, rect))
|
if (!texture->This->loadFromStream(sfmlStream, false, rect))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@@ -143,18 +116,13 @@ sfTexture* sfTexture_createSrgbFromStream(sfInputStream* stream, const sfIntRect
|
|||||||
{
|
{
|
||||||
assert(stream);
|
assert(stream);
|
||||||
|
|
||||||
auto* texture = new sfTexture;
|
const auto rect = area ? convertRect(*area) : sf::IntRect();
|
||||||
|
|
||||||
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
|
|
||||||
|
|
||||||
CallbackStream sfmlStream(stream);
|
CallbackStream sfmlStream(stream);
|
||||||
|
auto texture = std::make_unique<sfTexture>();
|
||||||
if (!texture->This->loadFromStream(sfmlStream, true, rect))
|
if (!texture->This->loadFromStream(sfmlStream, true, rect))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -163,17 +131,12 @@ sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area
|
|||||||
{
|
{
|
||||||
assert(image);
|
assert(image);
|
||||||
|
|
||||||
auto* texture = new sfTexture;
|
const auto rect = area ? convertRect(*area) : sf::IntRect();
|
||||||
|
auto texture = std::make_unique<sfTexture>();
|
||||||
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
|
|
||||||
|
|
||||||
if (!texture->This->loadFromImage(image->This, false, rect))
|
if (!texture->This->loadFromImage(image->This, false, rect))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@@ -181,17 +144,12 @@ sfTexture* sfTexture_createSrgbFromImage(const sfImage* image, const sfIntRect*
|
|||||||
{
|
{
|
||||||
assert(image);
|
assert(image);
|
||||||
|
|
||||||
auto* texture = new sfTexture;
|
const auto rect = area ? convertRect(*area) : sf::IntRect();
|
||||||
|
auto texture = std::make_unique<sfTexture>();
|
||||||
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
|
|
||||||
|
|
||||||
if (!texture->This->loadFromImage(image->This, true, rect))
|
if (!texture->This->loadFromImage(image->This, true, rect))
|
||||||
{
|
return nullptr;
|
||||||
delete texture;
|
|
||||||
texture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
return texture.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -32,20 +32,14 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfVertexBuffer* sfVertexBuffer_create(unsigned int vertexCount, sfPrimitiveType type, sfVertexBufferUsage usage)
|
sfVertexBuffer* sfVertexBuffer_create(unsigned int vertexCount, sfPrimitiveType type, sfVertexBufferUsage usage)
|
||||||
{
|
{
|
||||||
auto* buffer = new sfVertexBuffer;
|
sf::VertexBuffer buffer;
|
||||||
|
if (!buffer.create(vertexCount))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
if (!buffer->This.create(vertexCount))
|
buffer.setPrimitiveType(static_cast<sf::PrimitiveType>(type));
|
||||||
{
|
buffer.setUsage(static_cast<sf::VertexBuffer::Usage>(usage));
|
||||||
delete buffer;
|
|
||||||
buffer = nullptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buffer->This.setPrimitiveType(static_cast<sf::PrimitiveType>(type));
|
|
||||||
buffer->This.setUsage(static_cast<sf::VertexBuffer::Usage>(usage));
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer;
|
return new sfVertexBuffer{std::move(buffer)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#include <CSFML/Network/TcpListenerStruct.hpp>
|
#include <CSFML/Network/TcpListenerStruct.hpp>
|
||||||
#include <CSFML/Network/TcpSocketStruct.hpp>
|
#include <CSFML/Network/TcpSocketStruct.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sfTcpListener* sfTcpListener_create()
|
sfTcpListener* sfTcpListener_create()
|
||||||
@@ -90,14 +92,13 @@ sfSocketStatus sfTcpListener_accept(sfTcpListener* listener, sfTcpSocket** conne
|
|||||||
assert(listener);
|
assert(listener);
|
||||||
assert(connected);
|
assert(connected);
|
||||||
|
|
||||||
*connected = new sfTcpSocket;
|
auto socket = std::make_unique<sfTcpSocket>();
|
||||||
auto status = static_cast<sfSocketStatus>(listener->This.accept((*connected)->This));
|
auto status = static_cast<sfSocketStatus>(listener->This.accept(socket->This));
|
||||||
|
|
||||||
if (status != sfSocketDone)
|
if (status != sfSocketDone)
|
||||||
{
|
|
||||||
delete *connected;
|
|
||||||
*connected = nullptr;
|
*connected = nullptr;
|
||||||
}
|
else
|
||||||
|
*connected = socket.release();
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user