1
0
Fork 0

Fixes memory leak caused by J2DTextBox_SetString()

Setting the string on each frame fills up unallocated memory and causes
a hardlock.

Instead, call J2DTextBox_SetString() on stage load (since the memory is
freed level transition) and modify the already set string directly on
each frame.
This commit is contained in:
BitPatty 2017-01-31 01:18:03 +01:00
parent 646811b83c
commit 4ea2fc4749
2 changed files with 11 additions and 8 deletions

8
sms.c
View file

@ -6,7 +6,7 @@
#include "sms.h"
static J2DTextBox textbox;
static char* info;
int OnUpdate(MarDirector* director) {
int (*GameUpdate)(MarDirector* director) = GetObjectFunction(director, Director_GameUpdate);
@ -19,9 +19,8 @@ void OnDraw2D(J2DOrthoGraph* graphics)
{
Vector mariopos = **gpMarioPos;
int state = GetMarioStatus();
snprintf(info, 128, "Mario X: %f\nMario Y: %f\nMario Z: %f\nMario State: %X\nNext Stage: %d-%d",
snprintf(J2DTextBox_GetStringPtr(&textbox), 128, "Mario X: %f\nMario Y: %f\nMario Z: %f\nMario State: %X\nNext Stage: %d-%d",
mariopos.x, mariopos.y, mariopos.z, state, *ChangeScenario, *ChangeEpisode);
J2DTextBox_SetString(&textbox, info);
J2DGrafContext_Setup2D((J2DGrafContext*)graphics); //Run replaced branch
@ -39,5 +38,8 @@ void OnSetup(MarDirector* director)
//textbox = (J2DTextBox*)malloc(sizeof(J2DTextBox));
J2DTextBox_Create(&textbox, 0, &rect, GameFont, GameStrTable, 2, 0);
char* info;
info = (char*)malloc(128);
J2DTextBox_SetString(&textbox, info);
}

11
sms2.c
View file

@ -13,7 +13,7 @@
/* This code is always running, and is constantly updating. */
J2DTextBox textbox;
char* info;
bool inAir;
int timesjumped;
@ -59,10 +59,7 @@ void OnDraw2D(J2DOrthoGraph* graphics)
/* Here are his states that we read.
If Mario is doing said action, the return should be 1.
*/
snprintf(info, 128, "Time x %d", time);
// now we set our string to a J2DTextBox
J2DTextBox_SetString(&textbox, info);
snprintf(J2DTextBox_GetStringPtr(&textbox), 128, "Time x %d", time);
//Run replaced branch
J2DGrafContext_Setup2D((J2DGrafContext*)graphics);
@ -93,6 +90,10 @@ void OnSetup(MarDirector* director)
//textbox = (J2DTextBox*)malloc(sizeof(J2DTextBox));
J2DTextBox_Create(&textbox, 0, &rect, GameFont, GameStrTable, 2, 0);
char* info;
info = (char*)malloc(128);
J2DTextBox_SetString(&textbox, info);
void (*TestNull)(void) = 0x80247fa4;
TestNull();