diff options
| author | chriscamacho <chriscamacho@users.noreply.github.com> | 2019-09-19 12:28:01 +0100 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2019-09-19 13:28:01 +0200 |
| commit | 314c4061df021425bce7cd173ebfa9d371f414cb (patch) | |
| tree | f068fce9b111c0de0729dc14796baf3a596a3051 | |
| parent | 08165fed1884c9f8499ea1463b7e6831105ca52b (diff) | |
| download | raylib-314c4061df021425bce7cd173ebfa9d371f414cb.tar.gz raylib-314c4061df021425bce7cd173ebfa9d371f414cb.zip | |
fixs issue mem leak with LoadModel / OBJ and issue with -1 material index (#969)
| -rw-r--r-- | src/models.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/models.c b/src/models.c index 7c69553c..0d4c3619 100644 --- a/src/models.c +++ b/src/models.c @@ -669,7 +669,9 @@ Model LoadModel(const char *fileName) model.materials = (Material *)RL_CALLOC(model.materialCount, sizeof(Material)); model.materials[0] = LoadMaterialDefault(); - model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int)); + if (model.meshMaterial==NULL) { + model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int)); + } } return model; @@ -2860,6 +2862,11 @@ static Model LoadOBJ(const char *fileName) // Assign mesh material for current mesh model.meshMaterial[m] = attrib.material_ids[m]; + + // set unfound materials to default + if (model.meshMaterial[m] == -1) { + model.meshMaterial[m] = 0; + } } // Init model materials |
