Always use memnew(), and memdelete().

This commit is contained in:
Relintai 2024-01-25 16:41:17 +01:00
parent d28cdc7555
commit a1586d48ac
11 changed files with 19 additions and 19 deletions

View File

@ -467,7 +467,7 @@ void GameScene::socket_thread_func(void *data) {
ERR_PRINT("New connection! " + itos(a)); ERR_PRINT("New connection! " + itos(a));
client_sockets.push_back(client_socket); client_sockets.push_back(client_socket);
client_socket = new Socket(); client_socket = memnew(Socket());
} }
for (int i = 0; i < client_sockets.size(); ++i) { for (int i = 0; i < client_sockets.size(); ++i) {
@ -579,7 +579,7 @@ GameScene::GameScene() {
material.instance(); material.instance();
material->texture = texture; material->texture = texture;
sprite = new Sprite(); sprite = memnew(Sprite());
sprite->mesh_instance->material = material; sprite->mesh_instance->material = material;
sprite->width = 500; sprite->width = 500;
sprite->height = 500; sprite->height = 500;
@ -590,7 +590,7 @@ GameScene::GameScene() {
//sprite->region_height = 1.0 / 16.0; //sprite->region_height = 1.0 / 16.0;
sprite->update_mesh(); sprite->update_mesh();
tile_map = new TileMap(); tile_map = memnew(TileMap());
tile_map->material = material; tile_map->material = material;
tile_map->atlas_size_x = 2; tile_map->atlas_size_x = 2;
tile_map->atlas_size_y = 2; tile_map->atlas_size_y = 2;
@ -612,7 +612,7 @@ GameScene::GameScene() {
tile_map->transform.scale(Vector2(32, 32)); tile_map->transform.scale(Vector2(32, 32));
tile_map->transform.set_origin(Vector2(500, 500)); tile_map->transform.set_origin(Vector2(500, 500));
camera = new PerspectiveCamera(); camera = memnew(PerspectiveCamera());
Transform t = camera->get_camera_transform(); Transform t = camera->get_camera_transform();
//camera->width = 2; //camera->width = 2;
//camera->height = 2; //camera->height = 2;

View File

@ -218,7 +218,7 @@ public:
material.instance(); material.instance();
material->texture = texture; material->texture = texture;
sprite = new Sprite(); sprite = memnew(Sprite());
sprite->mesh_instance->material = material; sprite->mesh_instance->material = material;
sprite->width = 500; sprite->width = 500;
sprite->height = 500; sprite->height = 500;
@ -229,7 +229,7 @@ public:
//sprite->region_height = 1.0 / 16.0; //sprite->region_height = 1.0 / 16.0;
sprite->update_mesh(); sprite->update_mesh();
tile_map = new TileMap(); tile_map = memnew(TileMap());
tile_map->material = material; tile_map->material = material;
tile_map->atlas_size_x = 2; tile_map->atlas_size_x = 2;
tile_map->atlas_size_y = 2; tile_map->atlas_size_y = 2;
@ -251,7 +251,7 @@ public:
tile_map->transform.scale(Vector2(32, 32)); tile_map->transform.scale(Vector2(32, 32));
tile_map->transform.set_origin(Vector2(500, 500)); tile_map->transform.set_origin(Vector2(500, 500));
camera = new PerspectiveCamera(); camera = memnew(PerspectiveCamera());
Transform t = camera->get_camera_transform(); Transform t = camera->get_camera_transform();
//camera->width = 2; //camera->width = 2;
//camera->height = 2; //camera->height = 2;

View File

@ -159,7 +159,7 @@ String *RLogger::get_string_ptr(const char *p_prefix, const char *p_function, co
return s; return s;
} }
void RLogger::return_string_ptr(String *str) { void RLogger::return_string_ptr(String *str) {
delete str; memdelete(str);
} }
String *RLogger::get_trace_string_ptr(const int p_default_size) { String *RLogger::get_trace_string_ptr(const int p_default_size) {

View File

@ -479,7 +479,7 @@ void GameScene::socket_thread_func(void *data) {
ERR_PRINT("New connection! " + itos(a)); ERR_PRINT("New connection! " + itos(a));
client_sockets.push_back(client_socket); client_sockets.push_back(client_socket);
client_socket = new Socket(); client_socket = memnew(Socket());
} }
for (int i = 0; i < client_sockets.size(); ++i) { for (int i = 0; i < client_sockets.size(); ++i) {
@ -591,7 +591,7 @@ GameScene::GameScene() {
material.instance(); material.instance();
material->texture = texture; material->texture = texture;
sprite = new Sprite(); sprite = memnew(Sprite());
sprite->mesh_instance->material = material; sprite->mesh_instance->material = material;
sprite->width = 500; sprite->width = 500;
sprite->height = 500; sprite->height = 500;
@ -602,7 +602,7 @@ GameScene::GameScene() {
//sprite->region_height = 1.0 / 16.0; //sprite->region_height = 1.0 / 16.0;
sprite->update_mesh(); sprite->update_mesh();
tile_map = new TileMap(); tile_map = memnew(TileMap());
tile_map->material = material; tile_map->material = material;
tile_map->atlas_size_x = 2; tile_map->atlas_size_x = 2;
tile_map->atlas_size_y = 2; tile_map->atlas_size_y = 2;
@ -624,7 +624,7 @@ GameScene::GameScene() {
tile_map->transform.scale(Vector2(32, 32)); tile_map->transform.scale(Vector2(32, 32));
tile_map->transform.set_origin(Vector2(500, 500)); tile_map->transform.set_origin(Vector2(500, 500));
camera = new PerspectiveCamera(); camera = memnew(PerspectiveCamera());
Transform t = camera->get_camera_transform(); Transform t = camera->get_camera_transform();
//camera->width = 2; //camera->width = 2;
//camera->height = 2; //camera->height = 2;

View File

@ -4,7 +4,7 @@
//--STRIP //--STRIP
void Signal::connect_static(void (*func)(Signal *)) { void Signal::connect_static(void (*func)(Signal *)) {
StaticSignalEntry *se = new StaticSignalEntry(); StaticSignalEntry *se = memnew(StaticSignalEntry());
se->func = func; se->func = func;
entries.push_back(se); entries.push_back(se);

View File

@ -119,7 +119,7 @@ protected:
template <typename T> template <typename T>
void Signal::connect(T *obj, void (*func)(T*, Signal *)) { void Signal::connect(T *obj, void (*func)(T*, Signal *)) {
ClassSignalEntrySpec<T> *ce = new ClassSignalEntrySpec<T>(); ClassSignalEntrySpec<T> *ce = memnew(ClassSignalEntrySpec<T>());
ce->obj = obj; ce->obj = obj;
ce->func = func; ce->func = func;

View File

@ -1967,7 +1967,7 @@ Rect2 Image::get_used_rect() const {
} }
Ref<Image> Image::get_rect(const Rect2 &p_area) const { Ref<Image> Image::get_rect(const Rect2 &p_area) const {
Ref<Image> img = new Image(p_area.position.x, p_area.position.y, mipmaps, format); Ref<Image> img = memnew(Image(p_area.position.x, p_area.position.y, mipmaps, format));
img->blit_rect(Ref<Image>((Image *)this), p_area, Vector2(0, 0)); img->blit_rect(Ref<Image>((Image *)this), p_area, Vector2(0, 0));
return img; return img;
} }

View File

@ -73,5 +73,5 @@ Sprite::Sprite() {
} }
Sprite::~Sprite() { Sprite::~Sprite() {
delete mesh_instance; memdelete(mesh_instance);
} }

View File

@ -159,7 +159,7 @@ String *RLogger::get_string_ptr(const char *p_prefix, const char *p_function, co
return s; return s;
} }
void RLogger::return_string_ptr(String *str) { void RLogger::return_string_ptr(String *str) {
delete str; memdelete(str);
} }
String *RLogger::get_trace_string_ptr(const int p_default_size) { String *RLogger::get_trace_string_ptr(const int p_default_size) {

View File

@ -4,7 +4,7 @@
//--STRIP //--STRIP
void Signal::connect_static(void (*func)(Signal *)) { void Signal::connect_static(void (*func)(Signal *)) {
StaticSignalEntry *se = new StaticSignalEntry(); StaticSignalEntry *se = memnew(StaticSignalEntry());
se->func = func; se->func = func;
entries.push_back(se); entries.push_back(se);

View File

@ -119,7 +119,7 @@ protected:
template <typename T> template <typename T>
void Signal::connect(T *obj, void (*func)(T*, Signal *)) { void Signal::connect(T *obj, void (*func)(T*, Signal *)) {
ClassSignalEntrySpec<T> *ce = new ClassSignalEntrySpec<T>(); ClassSignalEntrySpec<T> *ce = memnew(ClassSignalEntrySpec<T>());
ce->obj = obj; ce->obj = obj;
ce->func = func; ce->func = func;