Chasing memory issues.
This commit is contained in:
parent
72a68fae8b
commit
c3491d973f
4 changed files with 27 additions and 16 deletions
|
@ -27,4 +27,7 @@
|
||||||
#include "../thirdparty/stb_ds.h"
|
#include "../thirdparty/stb_ds.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define ARRFREE(a) do { if (a != NULL) { arrfree(a); } break; } while(1)
|
||||||
|
|
||||||
|
|
||||||
#endif // ARRAY_H
|
#endif // ARRAY_H
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_OUTPUT
|
#ifdef DEBUG_OUTPUTx
|
||||||
#define debug(...) printf(__VA_ARGS__)
|
#define debug(...) printf(__VA_ARGS__)
|
||||||
#define MEMWATCH
|
#define MEMWATCH
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -720,14 +720,7 @@ int vecparser(char *programIn, VecByteCodeT *bytecode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unwind variables array if needed.
|
// Unwind variables array if needed.
|
||||||
/*
|
ARRFREE(variables);
|
||||||
if (variables != NULL) {
|
|
||||||
while (arrlen(variables) > 0) {
|
|
||||||
arrdel(variables, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
arrfree(variables);
|
|
||||||
|
|
||||||
// Unwind unresolved array if needed.
|
// Unwind unresolved array if needed.
|
||||||
if (unresolved != NULL) {
|
if (unresolved != NULL) {
|
||||||
|
|
29
src/vector.c
29
src/vector.c
|
@ -122,6 +122,7 @@ EVENT void menuVectorFileOpen(GtkWidget *object, gpointer userData);
|
||||||
EVENT void menuVectorFileSave(GtkWidget *object, gpointer userData);
|
EVENT void menuVectorFileSave(GtkWidget *object, gpointer userData);
|
||||||
EVENT void menuVectorFileSaveAs(GtkWidget *object, gpointer userData);
|
EVENT void menuVectorFileSaveAs(GtkWidget *object, gpointer userData);
|
||||||
EVENT void menuVectorHelpVector(GtkWidget *object, gpointer userData);
|
EVENT void menuVectorHelpVector(GtkWidget *object, gpointer userData);
|
||||||
|
static void releasePointList(VectorDataT *self);
|
||||||
static void renderBytecode(VecByteCodeT *bytecode, VectorDataT *self);
|
static void renderBytecode(VecByteCodeT *bytecode, VectorDataT *self);
|
||||||
EVENT void scaleVectorTraceImageValueChanged(GtkWidget *object, gpointer userData);
|
EVENT void scaleVectorTraceImageValueChanged(GtkWidget *object, gpointer userData);
|
||||||
static void setDirty(VectorDataT *self, gboolean dirty);
|
static void setDirty(VectorDataT *self, gboolean dirty);
|
||||||
|
@ -386,6 +387,11 @@ EVENT void editorVectorNotify(GtkWidget *sciWidget, gint ctrlID, struct SCNotifi
|
||||||
|
|
||||||
//debug("Notification %d\n", notifyData->modificationType);
|
//debug("Notification %d\n", notifyData->modificationType);
|
||||||
|
|
||||||
|
// Initialize bytecode data.
|
||||||
|
byteCode.bytes = NULL;
|
||||||
|
byteCode.length = 0;
|
||||||
|
byteCode.bufferSize = 0;
|
||||||
|
|
||||||
switch (notifyData->nmhdr.code) {
|
switch (notifyData->nmhdr.code) {
|
||||||
case SCN_MODIFIED:
|
case SCN_MODIFIED:
|
||||||
if (notifyData->modificationType & SC_MOD_INSERTTEXT || notifyData->modificationType & SC_MOD_DELETETEXT) {
|
if (notifyData->modificationType & SC_MOD_INSERTTEXT || notifyData->modificationType & SC_MOD_DELETETEXT) {
|
||||||
|
@ -399,9 +405,6 @@ EVENT void editorVectorNotify(GtkWidget *sciWidget, gint ctrlID, struct SCNotifi
|
||||||
// Fetch code.
|
// Fetch code.
|
||||||
SSM(SCI_GETTEXT, length, (sptr_t)self->buffer);
|
SSM(SCI_GETTEXT, length, (sptr_t)self->buffer);
|
||||||
// Parse code.
|
// Parse code.
|
||||||
byteCode.bytes = NULL;
|
|
||||||
byteCode.length = 0;
|
|
||||||
byteCode.bufferSize = 0;
|
|
||||||
lineNumber = vecparser(self->buffer, &byteCode);
|
lineNumber = vecparser(self->buffer, &byteCode);
|
||||||
if (lineNumber >= 0) {
|
if (lineNumber >= 0) {
|
||||||
// Mark lines that fail to parse.
|
// Mark lines that fail to parse.
|
||||||
|
@ -569,7 +572,7 @@ static void loadTraceImage(VectorDataT *self, char *filename) {
|
||||||
cairo_surface_flush(temp);
|
cairo_surface_flush(temp);
|
||||||
pixels = cairo_image_surface_get_data(temp);
|
pixels = cairo_image_surface_get_data(temp);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
while (offset < x * y * 4) {
|
while (offset < x * y * 4 - 4) { // Not sure why we need the -4 but it keeps us from going one byte off the end of pixels[].
|
||||||
pixels[offset + 2] = image[offset ]; // R
|
pixels[offset + 2] = image[offset ]; // R
|
||||||
pixels[offset + 1] = image[offset + 1]; // G
|
pixels[offset + 1] = image[offset + 1]; // G
|
||||||
pixels[offset ] = image[offset + 2]; // B
|
pixels[offset ] = image[offset + 2]; // B
|
||||||
|
@ -834,6 +837,17 @@ EVENT void menuVectorHelpVector(GtkWidget *object, gpointer userData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void releasePointList(VectorDataT *self) {
|
||||||
|
PointT *temp;
|
||||||
|
|
||||||
|
while (arrlen(self->pointList) > 0) {
|
||||||
|
temp = self->pointList[0];
|
||||||
|
arrdel(self->pointList, 0);
|
||||||
|
DEL(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void renderBytecode(VecByteCodeT *bytecode, VectorDataT *self) {
|
static void renderBytecode(VecByteCodeT *bytecode, VectorDataT *self) {
|
||||||
int x1;
|
int x1;
|
||||||
int y1;
|
int y1;
|
||||||
|
@ -856,7 +870,7 @@ static void renderBytecode(VecByteCodeT *bytecode, VectorDataT *self) {
|
||||||
debug("-----------------------------------\n");
|
debug("-----------------------------------\n");
|
||||||
|
|
||||||
// Clear collected points array.
|
// Clear collected points array.
|
||||||
arrfree(self->pointList);
|
releasePointList(self);
|
||||||
|
|
||||||
// Reset JoeyLib draw state.
|
// Reset JoeyLib draw state.
|
||||||
jlPaletteDefault(self->jlc);
|
jlPaletteDefault(self->jlc);
|
||||||
|
@ -1143,10 +1157,10 @@ static void renderBytecode(VecByteCodeT *bytecode, VectorDataT *self) {
|
||||||
debug("Points: %ld\n", arrlen(self->pointList));
|
debug("Points: %ld\n", arrlen(self->pointList));
|
||||||
|
|
||||||
// Clear variables.
|
// Clear variables.
|
||||||
arrfree(self->variables);
|
ARRFREE(self->variables);
|
||||||
|
|
||||||
// Clear stack.
|
// Clear stack.
|
||||||
arrfree(stack);
|
ARRFREE(stack);
|
||||||
|
|
||||||
// Refresh widget.
|
// Refresh widget.
|
||||||
gtk_widget_queue_draw(self->drawVectorImage);
|
gtk_widget_queue_draw(self->drawVectorImage);
|
||||||
|
@ -1550,6 +1564,7 @@ static void winVectorDelete(gpointer userData) {
|
||||||
cairo_surface_destroy(self->scaled);
|
cairo_surface_destroy(self->scaled);
|
||||||
cairo_surface_destroy(self->target);
|
cairo_surface_destroy(self->target);
|
||||||
if (self->trace != NULL) cairo_surface_destroy(self->trace);
|
if (self->trace != NULL) cairo_surface_destroy(self->trace);
|
||||||
|
releasePointList(self);
|
||||||
DEL(self->filename);
|
DEL(self->filename);
|
||||||
DEL(self->title);
|
DEL(self->title);
|
||||||
DEL(self->tracename);
|
DEL(self->tracename);
|
||||||
|
|
Loading…
Add table
Reference in a new issue