From c4638880aec76fddbcfdbbbf3d07d3072a925053 Mon Sep 17 00:00:00 2001 From: Potter360 Date: Thu, 5 Jan 2023 16:10:57 +0100 Subject: [PATCH] debug error when not enough memory in from_mesh --- src/windmill_utility.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/windmill_utility.cpp b/src/windmill_utility.cpp index bb5c430..5449808 100644 --- a/src/windmill_utility.cpp +++ b/src/windmill_utility.cpp @@ -201,6 +201,11 @@ void WMesh::from_mesh(const Mesh* mesh, int margin) v_length = mesh->v_length; v_length_allocated = mesh->v_length * margin; v = (Vertex*) malloc(v_length_allocated * sizeof(Vertex)); + if(v == NULL){ + debug_pop("FATAL ERROR IN \nALLOCATION OF VERTEX\n(WMesh::from_mesh)"); + debug_pop("TOTAL MALLOC SIZE : \n%i", v_length_allocated * sizeof(Vertex)); + exit(0); + } for (int i = 0; i < mesh->v_length; i++) { //v[i].FromVertexPoint(mesh->v[i]) @@ -212,11 +217,21 @@ void WMesh::from_mesh(const Mesh* mesh, int margin) t_length = mesh->t_length; t_length_allocated = mesh->t_length * margin; t = (TexturePoint*) malloc(t_length_allocated * sizeof(TexturePoint)); + if(t == NULL){ + debug_pop("FATAL ERROR IN \nALLOCATION OF TEXTURE\n (WMesh::from_mesh)"); + debug_pop("TOTAL MALLOC SIZE : \n%i", t_length_allocated * sizeof(TexturePoint)); + exit(0); + } memcpy(t, mesh->t, mesh->t_length * sizeof(TexturePoint)); f_length = mesh->f_length; f_length_allocated = mesh->f_length * margin; f = (Face*) malloc(f_length_allocated * sizeof(Face)); + if(f == NULL){ + debug_pop("FATAL ERROR IN \nALLOCATION OF FACE\nWMesh::from_mesh)"); + debug_pop("TOTAL MALLOC SIZE : \n%i" + f_length_allocated * sizeof(Face)); + exit(0); + } memcpy(f, mesh->f, mesh->f_length * sizeof(Face)); }