DRW: Fix crash caused by fixing the leak (badly).

Previous commit was af425f3f7a
This commit is contained in:
2018-02-08 00:40:50 +01:00
parent 44aaffc684
commit 42c99ee5f5
3 changed files with 10 additions and 3 deletions

View File

@@ -38,8 +38,6 @@
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
#define MAX_INSTANCE_DATA_SIZE 32 /* Can be adjusted for more */
struct DRWInstanceData {
struct DRWInstanceData *next;
bool used; /* If this data is used or not. */

View File

@@ -26,6 +26,8 @@
#ifndef __DRAW_INSTANCE_DATA_H__
#define __DRAW_INSTANCE_DATA_H__
#define MAX_INSTANCE_DATA_SIZE 42 /* Can be adjusted for more */
typedef struct DRWInstanceData DRWInstanceData;
typedef struct DRWInstanceDataList DRWInstanceDataList;

View File

@@ -315,6 +315,7 @@ static struct DRWGlobalState {
DRWCallGenerate *last_callgenerate;
DRWShadingGroup *last_shgroup;
DRWInstanceDataList *idatalist;
DRWInstanceData *common_instance_data[MAX_INSTANCE_DATA_SIZE];
/* Rendering state */
GPUShader *shader;
@@ -2676,6 +2677,7 @@ static void drw_viewport_var_init(void)
}
memset(viewport_matrix_override.override, 0x0, sizeof(viewport_matrix_override.override));
memset(DST.common_instance_data, 0x0, sizeof(DST.common_instance_data));
}
void DRW_viewport_matrix_get(float mat[4][4], DRWViewportMatrixType type)
@@ -2824,10 +2826,15 @@ ObjectEngineData *DRW_object_engine_data_ensure(
/* Allocate new data. */
if ((ob->base_flag & BASE_FROMDUPLI) != 0) {
/* NOTE: data is not persistent in this case. It is reset each redraw. */
BLI_assert(free_cb == NULL); /* No callback allowed. */
/* Round to sizeof(float) for DRW_instance_data_request(). */
const size_t t = sizeof(float) - 1;
size = (size + t) & ~t;
oed = (ObjectEngineData *)DRW_instance_data_request(DST.idatalist, size / sizeof(float), 16);
size_t fsize = size / sizeof(float);
if (DST.common_instance_data[fsize] == NULL) {
DST.common_instance_data[fsize] = DRW_instance_data_request(DST.idatalist, fsize, 16);
}
oed = (ObjectEngineData *)DRW_instance_data_next(DST.common_instance_data[fsize]);
memset(oed, 0, size);
}
else {