3434#include < CSFML/System/ConvertVector2.hpp>
3535#include < CSFML/Window/WindowStruct.hpp>
3636
37+ #include < memory>
38+
3739
3840// //////////////////////////////////////////////////////////
3941sfTexture* sfTexture_create (sfVector2u size)
4042{
41- auto * texture = new sfTexture;
42-
43+ auto texture = std::make_unique<sfTexture>();
4344 if (!texture->This ->resize (convertVector2 (size)))
44- {
45- delete texture;
46- texture = nullptr ;
47- }
45+ return nullptr ;
4846
49- return texture;
47+ return texture. release () ;
5048}
5149
5250
@@ -55,106 +53,75 @@ sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area)
5553{
5654 assert (filename);
5755
58- auto * texture = new sfTexture;
59-
60- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
61-
56+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
57+ auto texture = std::make_unique<sfTexture>();
6258 if (!texture->This ->loadFromFile (filename, false , rect))
63- {
64- delete texture;
65- texture = nullptr ;
66- }
59+ return nullptr ;
6760
68- return texture;
61+ return texture. release () ;
6962}
7063
7164// //////////////////////////////////////////////////////////
7265sfTexture* sfTexture_createSrgbFromFile (const char * filename, const sfIntRect* area)
7366{
7467 assert (filename);
7568
76- auto * texture = new sfTexture;
77-
78- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
79-
69+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
70+ auto texture = std::make_unique<sfTexture>();
8071 if (!texture->This ->loadFromFile (filename, true , rect))
81- {
82- delete texture;
83- texture = nullptr ;
84- }
72+ return nullptr ;
8573
86- return texture;
74+ return texture. release () ;
8775}
8876
8977// //////////////////////////////////////////////////////////
9078sfTexture* sfTexture_createFromMemory (const void * data, size_t sizeInBytes, const sfIntRect* area)
9179{
92- auto * texture = new sfTexture;
93-
94- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
95-
80+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
81+ auto texture = std::make_unique<sfTexture>();
9682 if (!texture->This ->loadFromMemory (data, sizeInBytes, false , rect))
97- {
98- delete texture;
99- texture = nullptr ;
100- }
83+ return nullptr ;
10184
102- return texture;
85+ return texture. release () ;
10386}
10487
10588// //////////////////////////////////////////////////////////
10689sfTexture* sfTexture_createSrgbFromMemory (const void * data, size_t sizeInBytes, const sfIntRect* area)
10790{
108- auto * texture = new sfTexture;
109-
110- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
111-
91+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
92+ auto texture = std::make_unique<sfTexture>();
11293 if (!texture->This ->loadFromMemory (data, sizeInBytes, true , rect))
113- {
114- delete texture;
115- texture = nullptr ;
116- }
94+ return nullptr ;
11795
118- return texture;
96+ return texture. release () ;
11997}
12098
12199
122100// //////////////////////////////////////////////////////////
123101sfTexture* sfTexture_createFromStream (sfInputStream* stream, const sfIntRect* area)
124102{
125103 assert (stream);
126-
127- auto * texture = new sfTexture;
128-
129- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
130-
104+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
131105 CallbackStream sfmlStream (stream);
106+ auto texture = std::make_unique<sfTexture>();
132107 if (!texture->This ->loadFromStream (sfmlStream, false , rect))
133- {
134- delete texture;
135- texture = nullptr ;
136- }
108+ return nullptr ;
137109
138- return texture;
110+ return texture. release () ;
139111}
140112
141113// //////////////////////////////////////////////////////////
142114sfTexture* sfTexture_createSrgbFromStream (sfInputStream* stream, const sfIntRect* area)
143115{
144116 assert (stream);
145117
146- auto * texture = new sfTexture;
147-
148- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
149-
118+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
150119 CallbackStream sfmlStream (stream);
120+ auto texture = std::make_unique<sfTexture>();
151121 if (!texture->This ->loadFromStream (sfmlStream, true , rect))
152- {
153- delete texture;
154- texture = nullptr ;
155- }
122+ return nullptr ;
156123
157- return texture;
124+ return texture. release () ;
158125}
159126
160127
@@ -163,35 +130,25 @@ sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area
163130{
164131 assert (image);
165132
166- auto * texture = new sfTexture;
167-
168- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
169-
133+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
134+ auto texture = std::make_unique<sfTexture>();
170135 if (!texture->This ->loadFromImage (image->This , false , rect))
171- {
172- delete texture;
173- texture = nullptr ;
174- }
136+ return nullptr ;
175137
176- return texture;
138+ return texture. release () ;
177139}
178140
179141// //////////////////////////////////////////////////////////
180142sfTexture* sfTexture_createSrgbFromImage (const sfImage* image, const sfIntRect* area)
181143{
182144 assert (image);
183145
184- auto * texture = new sfTexture;
185-
186- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
187-
146+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
147+ auto texture = std::make_unique<sfTexture>();
188148 if (!texture->This ->loadFromImage (image->This , true , rect))
189- {
190- delete texture;
191- texture = nullptr ;
192- }
149+ return nullptr ;
193150
194- return texture;
151+ return texture. release () ;
195152}
196153
197154// //////////////////////////////////////////////////////////
0 commit comments