1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-21 20:39:57 +01:00

Fix memory error

This commit is contained in:
Miloslav Číž 2019-05-28 19:48:36 +02:00
parent e7dc709ebd
commit d8dd1ec04a
2 changed files with 15 additions and 12 deletions

View file

@ -148,8 +148,7 @@
triangles. */ triangles. */
/* === PRESETS === /* === PRESETS ===
These can be used to quickly set a predefined library behavior. These can be used to quickly set a predefined library behavior. */
*/
#ifdef S3L_PRESET_HIGHEST_QUALITY #ifdef S3L_PRESET_HIGHEST_QUALITY
#define S3L_Z_BUFFER S3L_Z_BUFFER_FULL #define S3L_Z_BUFFER S3L_Z_BUFFER_FULL
@ -159,6 +158,7 @@
#ifdef S3L_PRESET_EMBEDDED #ifdef S3L_PRESET_EMBEDDED
#define S3L_Z_BUFFER S3L_Z_BUFFER_NONE #define S3L_Z_BUFFER S3L_Z_BUFFER_NONE
#define S3L_COMPUTE_DEPTH 0
#define S3L_PERSPECTIVE_CORRECTION 0 #define S3L_PERSPECTIVE_CORRECTION 0
#define S3L_NEAR_CLAMPING 0 #define S3L_NEAR_CLAMPING 0
#define S3L_SORT S3L_SORT_BACK_TO_FRONT #define S3L_SORT S3L_SORT_BACK_TO_FRONT
@ -1925,17 +1925,20 @@ void S3L_drawScene(S3L_Scene scene)
for (modelIndex = 0; modelIndex < scene.modelCount; ++modelIndex) for (modelIndex = 0; modelIndex < scene.modelCount; ++modelIndex)
{ {
#if S3L_SORT != S3L_SORT_NONE
if (S3L_sortArrayLength >= S3L_MAX_TRIANGES_DRAWN)
break;
previousModel = modelIndex;
#endif
S3L_makeWorldMatrix(scene.models[modelIndex].transform,&matFinal); S3L_makeWorldMatrix(scene.models[modelIndex].transform,&matFinal);
S3L_mat4Xmat4(&matFinal,&matCamera); S3L_mat4Xmat4(&matFinal,&matCamera);
S3L_Index triangleCount = scene.models[modelIndex].triangleCount; S3L_Index triangleCount = scene.models[modelIndex].triangleCount;
triangleIndex = 0; triangleIndex = 0;
#if S3L_SORT != S3L_SORT_NONE
previousModel = modelIndex;
#endif
while (triangleIndex < triangleCount) while (triangleIndex < triangleCount)
{ {
model = &(scene.models[modelIndex]); model = &(scene.models[modelIndex]);
@ -1960,6 +1963,9 @@ void S3L_drawScene(S3L_Scene scene)
S3L_drawTriangle(transformed0,transformed1,transformed2, S3L_drawTriangle(transformed0,transformed1,transformed2,
&(model->config),&(scene.camera),modelIndex,triangleIndex); &(model->config),&(scene.camera),modelIndex,triangleIndex);
#else #else
if (S3L_sortArrayLength >= S3L_MAX_TRIANGES_DRAWN)
break;
// with sorting add to a sort list // with sorting add to a sort list
S3L_sortArray[S3L_sortArrayLength].modelIndex = modelIndex; S3L_sortArray[S3L_sortArrayLength].modelIndex = modelIndex;
S3L_sortArray[S3L_sortArrayLength].triangleIndex = triangleIndex; S3L_sortArray[S3L_sortArrayLength].triangleIndex = triangleIndex;
@ -1973,7 +1979,8 @@ void S3L_drawScene(S3L_Scene scene)
S3L_sortArrayLength++; S3L_sortArrayLength++;
#endif #endif
} }
++triangleIndex;
triangleIndex++;
} }
} }

View file

@ -14,10 +14,6 @@
#define S3L_RESOLUTION_X 640 #define S3L_RESOLUTION_X 640
#define S3L_RESOLUTION_Y 480 #define S3L_RESOLUTION_Y 480
#define S3L_COMPUTE_DEPTH 1
#define S3L_PERSPECTIVE_CORRECTION 1
#define S3L_NEAR_CLAMPING 1
#include "small3dlib.h" #include "small3dlib.h"
#include "house.h" #include "house.h"