fixed huge memory leak when calling chunk_render on empty section
This commit is contained in:
@@ -187,6 +187,26 @@ int load_chunk(RenderState* state, int x, int z, unsigned char required) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* helper to unload all loaded chunks */
|
||||||
|
static void
|
||||||
|
unload_all_chunks(RenderState *state) {
|
||||||
|
unsigned int i, j, k;
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
for (j = 0; j < 3; j++) {
|
||||||
|
if (state->chunks[i][j].loaded) {
|
||||||
|
Py_XDECREF(state->chunks[i][j].biomes);
|
||||||
|
for (k = 0; k < SECTIONS_PER_CHUNK; k++) {
|
||||||
|
Py_XDECREF(state->chunks[i][j].sections[k].blocks);
|
||||||
|
Py_XDECREF(state->chunks[i][j].sections[k].data);
|
||||||
|
Py_XDECREF(state->chunks[i][j].sections[k].skylight);
|
||||||
|
Py_XDECREF(state->chunks[i][j].sections[k].blocklight);
|
||||||
|
}
|
||||||
|
state->chunks[i][j].loaded = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char
|
unsigned char
|
||||||
check_adjacent_blocks(RenderState *state, int x,int y,int z, unsigned char blockid) {
|
check_adjacent_blocks(RenderState *state, int x,int y,int z, unsigned char blockid) {
|
||||||
/*
|
/*
|
||||||
@@ -484,6 +504,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
|||||||
/* this section doesn't exist, let's skeddadle */
|
/* this section doesn't exist, let's skeddadle */
|
||||||
render_mode_destroy(rendermode);
|
render_mode_destroy(rendermode);
|
||||||
Py_DECREF(blockmap);
|
Py_DECREF(blockmap);
|
||||||
|
unload_all_chunks(&state);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,21 +622,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
|||||||
render_mode_destroy(rendermode);
|
render_mode_destroy(rendermode);
|
||||||
|
|
||||||
Py_DECREF(blockmap);
|
Py_DECREF(blockmap);
|
||||||
for (i = 0; i < 3; i++) {
|
unload_all_chunks(&state);
|
||||||
for (j = 0; j < 3; j++) {
|
|
||||||
if (state.chunks[i][j].loaded) {
|
|
||||||
int k;
|
|
||||||
Py_XDECREF(state.chunks[i][j].biomes);
|
|
||||||
for (k = 0; k < SECTIONS_PER_CHUNK; k++) {
|
|
||||||
Py_XDECREF(state.chunks[i][j].sections[k].blocks);
|
|
||||||
Py_XDECREF(state.chunks[i][j].sections[k].data);
|
|
||||||
Py_XDECREF(state.chunks[i][j].sections[k].skylight);
|
|
||||||
Py_XDECREF(state.chunks[i][j].sections[k].blocklight);
|
|
||||||
}
|
|
||||||
state.chunks[i][j].loaded = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
// increment this value if you've made a change to the c extesion
|
// increment this value if you've made a change to the c extesion
|
||||||
// and want to force users to rebuild
|
// and want to force users to rebuild
|
||||||
#define OVERVIEWER_EXTENSION_VERSION 26
|
#define OVERVIEWER_EXTENSION_VERSION 27
|
||||||
|
|
||||||
/* Python PIL, and numpy headers */
|
/* Python PIL, and numpy headers */
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user