Whoa. Bad memory fubar in jlImgCreate(). Fixed.

This commit is contained in:
Scott Duensing 2020-08-10 17:54:18 -05:00
parent a6004882dd
commit 91f0b44a33
3 changed files with 16 additions and 16 deletions

View file

@ -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';

View file

@ -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';

View file

@ -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();