From 91f0b44a33bc9597de109c9bc49720de8bcc34e9 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Mon, 10 Aug 2020 17:54:18 -0500 Subject: [PATCH] Whoa. Bad memory fubar in jlImgCreate(). Fixed. --- joeylib/src/jIIgs.c | 8 +------- joeylib/src/jSDL2.c | 2 +- joeylib/src/test.c | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/joeylib/src/jIIgs.c b/joeylib/src/jIIgs.c index 87e9638..6935a14 100644 --- a/joeylib/src/jIIgs.c +++ b/joeylib/src/jIIgs.c @@ -132,23 +132,17 @@ void jlDrawSurfaceSet(jlSurfaceT target) { int jlGameGetAxis(byte which) { - static bool xRead = true; - static bool yRead = true; static jint16 paddles = 0; jint16 r; if (which == 0) { if (xRead) { paddles = asmJoy(); - xRead = true; - yRead = false; } r = paddles & 0x00ff; } else { if (yRead) { paddles = asmJoy(); - xRead = false; - yRead = true; } r = (paddles & 0xff00) >> 8; } @@ -174,7 +168,7 @@ bool _jlImgCreate(jlImgT **img) { } *img = t; } - memset(t, 0, sizeof(jlImgT)); + t = (jlImgT *)*img; t->id[0] = 'I'; t->id[1] = 'M'; t->id[2] = 'G'; diff --git a/joeylib/src/jSDL2.c b/joeylib/src/jSDL2.c index 1d27551..94e4e36 100644 --- a/joeylib/src/jSDL2.c +++ b/joeylib/src/jSDL2.c @@ -428,7 +428,7 @@ bool _jlImgCreate(jlImgT **img) { } *img = t; } - memset(t, 0, sizeof(jlImgT)); + t = (jlImgT *)*img; t->id[0] = 'I'; t->id[1] = 'M'; t->id[2] = 'G'; diff --git a/joeylib/src/test.c b/joeylib/src/test.c index 641505b..7c3d600 100644 --- a/joeylib/src/test.c +++ b/joeylib/src/test.c @@ -77,7 +77,7 @@ void help(jlSurfaceT source, jlStnT *stencil, jint16 sx, jint16 sy, jint16 tx, j // Font hacking! __attribute__((__format__ (__printf__, 5, 0))) -void printAt(jlImgT *font, jlStnT *stencil, jint16 cx, jint16 cy, const char *what, ...) { +void fontPrint(jlImgT *font, jlStnT *stencil, jint16 cx, jint16 cy, const char *what, ...) { jint16 x; jint16 y; jint16 tx; @@ -127,8 +127,8 @@ void blitTest(void) { jlDrawClear(); jlPaletteSet(15, 15, 15, 15); - printAt(font, NULL, 1, 2, "%s", "Blitting without stencil buffer."); - printAt(font, stencil, 1, 4, "%s", "Blitting with stencil buffer."); + fontPrint(font, NULL, 1, 2, "%s", "Blitting without stencil buffer."); + fontPrint(font, stencil, 1, 4, "%s", "Blitting with stencil buffer."); jlDisplayPresent(); jlKeyWaitForAny(); @@ -136,7 +136,7 @@ void blitTest(void) { while (!jlKeyPressed()) { for (x=0; x<319-8; x++) { jlDrawBlit8x8(jlImgSurfaceGet(font), 8, 0, x, y); - printAt(font, NULL, 1, 6, "Drawing at %d x %d ", x, y); + fontPrint(font, NULL, 1, 6, "Drawing at %d x %d ", x, y); jlDisplayPresent(); jlDrawBlit8x8(jlImgSurfaceGet(font), 0, 0, x, y); jlUtilSleep(1); @@ -154,6 +154,8 @@ void blitTest(void) { void exerciseAPI(void) { + jlImgT *screen = NULL; + jlDrawColorSet(0); jlDrawClear(); jlDrawColorSet(15); @@ -161,6 +163,10 @@ void exerciseAPI(void) { jlDrawPixelSet(10, 10); assert(jlDrawPixelGet(10, 10) == 15); + // Should be able to grab the screen twice without allocation issues. + jlImgCreate(screen); + jlImgCreate(screen); + jlImgFree(screen); } @@ -214,7 +220,7 @@ void lineTest(void) { while (!jlKeyPressed()) { y = 17; - printAt(font, NULL, 1, y++, "Drawing %s ", what); + fontPrint(font, NULL, 1, y++, "Drawing %s ", what); jlDrawColorSet((byte)color); if (phase < 2) { @@ -299,7 +305,7 @@ void musicTest(void) { jlSoundModPlay("music"); while (!jlKeyPressed()) { - printAt(font, NULL, 1, 1, "%dx%d %d %d ", jlGameGetAxis(0), jlGameGetAxis(1), jlGameGetButton(0), jlGameGetButton(1)); + fontPrint(font, NULL, 1, 1, "%dx%d %d %d ", jlGameGetAxis(0), jlGameGetAxis(1), jlGameGetButton(0), jlGameGetButton(1)); jlDisplayPresent(); } jlKeyRead(); @@ -370,10 +376,10 @@ int main(void) { jlUtilStartup("JoeyLib Test"); //blitTest(); - //exerciseAPI(); + exerciseAPI(); //grid(); //lineTest(); - musicTest(); + //musicTest(); //showStencil(); jlUtilShutdown();