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,67 +53,47 @@ 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
@@ -124,37 +102,27 @@ sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* ar
124102{
125103 assert (stream);
126104
127- auto * texture = new sfTexture;
128-
129- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
130-
105+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
131106 CallbackStream sfmlStream (stream);
107+ auto texture = std::make_unique<sfTexture>();
132108 if (!texture->This ->loadFromStream (sfmlStream, false , rect))
133- {
134- delete texture;
135- texture = nullptr ;
136- }
109+ return nullptr ;
137110
138- return texture;
111+ return texture. release () ;
139112}
140113
141114// //////////////////////////////////////////////////////////
142115sfTexture* sfTexture_createSrgbFromStream (sfInputStream* stream, const sfIntRect* area)
143116{
144117 assert (stream);
145118
146- auto * texture = new sfTexture;
147-
148- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
149-
119+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
150120 CallbackStream sfmlStream (stream);
121+ auto texture = std::make_unique<sfTexture>();
151122 if (!texture->This ->loadFromStream (sfmlStream, true , rect))
152- {
153- delete texture;
154- texture = nullptr ;
155- }
123+ return nullptr ;
156124
157- return texture;
125+ return texture. release () ;
158126}
159127
160128
@@ -163,35 +131,25 @@ sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area
163131{
164132 assert (image);
165133
166- auto * texture = new sfTexture;
167-
168- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
169-
134+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
135+ auto texture = std::make_unique<sfTexture>();
170136 if (!texture->This ->loadFromImage (image->This , false , rect))
171- {
172- delete texture;
173- texture = nullptr ;
174- }
137+ return nullptr ;
175138
176- return texture;
139+ return texture. release () ;
177140}
178141
179142// //////////////////////////////////////////////////////////
180143sfTexture* sfTexture_createSrgbFromImage (const sfImage* image, const sfIntRect* area)
181144{
182145 assert (image);
183146
184- auto * texture = new sfTexture;
185-
186- const sf::IntRect rect = area ? convertRect (*area) : sf::IntRect ();
187-
147+ const auto rect = area ? convertRect (*area) : sf::IntRect ();
148+ auto texture = std::make_unique<sfTexture>();
188149 if (!texture->This ->loadFromImage (image->This , true , rect))
189- {
190- delete texture;
191- texture = nullptr ;
192- }
150+ return nullptr ;
193151
194- return texture;
152+ return texture. release () ;
195153}
196154
197155// //////////////////////////////////////////////////////////
0 commit comments