Merge pull request #1 from BitPatty/master
Fixes memory leak caused by J2DTextBox_SetString()
This commit is contained in:
commit
db3246fb8c
2 changed files with 11 additions and 8 deletions
8
sms.c
8
sms.c
|
@ -6,7 +6,7 @@
|
||||||
#include "sms.h"
|
#include "sms.h"
|
||||||
|
|
||||||
static J2DTextBox textbox;
|
static J2DTextBox textbox;
|
||||||
static char* info;
|
|
||||||
int OnUpdate(MarDirector* director) {
|
int OnUpdate(MarDirector* director) {
|
||||||
int (*GameUpdate)(MarDirector* director) = GetObjectFunction(director, Director_GameUpdate);
|
int (*GameUpdate)(MarDirector* director) = GetObjectFunction(director, Director_GameUpdate);
|
||||||
|
|
||||||
|
@ -19,9 +19,8 @@ void OnDraw2D(J2DOrthoGraph* graphics)
|
||||||
{
|
{
|
||||||
Vector mariopos = **gpMarioPos;
|
Vector mariopos = **gpMarioPos;
|
||||||
int state = GetMarioStatus();
|
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);
|
mariopos.x, mariopos.y, mariopos.z, state, *ChangeScenario, *ChangeEpisode);
|
||||||
J2DTextBox_SetString(&textbox, info);
|
|
||||||
|
|
||||||
J2DGrafContext_Setup2D((J2DGrafContext*)graphics); //Run replaced branch
|
J2DGrafContext_Setup2D((J2DGrafContext*)graphics); //Run replaced branch
|
||||||
|
|
||||||
|
@ -39,5 +38,8 @@ void OnSetup(MarDirector* director)
|
||||||
//textbox = (J2DTextBox*)malloc(sizeof(J2DTextBox));
|
//textbox = (J2DTextBox*)malloc(sizeof(J2DTextBox));
|
||||||
J2DTextBox_Create(&textbox, 0, &rect, GameFont, GameStrTable, 2, 0);
|
J2DTextBox_Create(&textbox, 0, &rect, GameFont, GameStrTable, 2, 0);
|
||||||
|
|
||||||
|
char* info;
|
||||||
info = (char*)malloc(128);
|
info = (char*)malloc(128);
|
||||||
|
|
||||||
|
J2DTextBox_SetString(&textbox, info);
|
||||||
}
|
}
|
11
sms2.c
11
sms2.c
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
/* This code is always running, and is constantly updating. */
|
/* This code is always running, and is constantly updating. */
|
||||||
J2DTextBox textbox;
|
J2DTextBox textbox;
|
||||||
char* info;
|
|
||||||
|
|
||||||
bool inAir;
|
bool inAir;
|
||||||
int timesjumped;
|
int timesjumped;
|
||||||
|
@ -59,10 +59,7 @@ void OnDraw2D(J2DOrthoGraph* graphics)
|
||||||
/* Here are his states that we read.
|
/* Here are his states that we read.
|
||||||
If Mario is doing said action, the return should be 1.
|
If Mario is doing said action, the return should be 1.
|
||||||
*/
|
*/
|
||||||
snprintf(info, 128, "Time x %d", time);
|
snprintf(J2DTextBox_GetStringPtr(&textbox), 128, "Time x %d", time);
|
||||||
|
|
||||||
// now we set our string to a J2DTextBox
|
|
||||||
J2DTextBox_SetString(&textbox, info);
|
|
||||||
|
|
||||||
//Run replaced branch
|
//Run replaced branch
|
||||||
J2DGrafContext_Setup2D((J2DGrafContext*)graphics);
|
J2DGrafContext_Setup2D((J2DGrafContext*)graphics);
|
||||||
|
@ -93,6 +90,10 @@ void OnSetup(MarDirector* director)
|
||||||
//textbox = (J2DTextBox*)malloc(sizeof(J2DTextBox));
|
//textbox = (J2DTextBox*)malloc(sizeof(J2DTextBox));
|
||||||
J2DTextBox_Create(&textbox, 0, &rect, GameFont, GameStrTable, 2, 0);
|
J2DTextBox_Create(&textbox, 0, &rect, GameFont, GameStrTable, 2, 0);
|
||||||
|
|
||||||
|
char* info;
|
||||||
|
info = (char*)malloc(128);
|
||||||
|
J2DTextBox_SetString(&textbox, info);
|
||||||
|
|
||||||
void (*TestNull)(void) = 0x80247fa4;
|
void (*TestNull)(void) = 0x80247fa4;
|
||||||
TestNull();
|
TestNull();
|
||||||
|
|
||||||
|
|
Reference in a new issue