mirror of
https://github.com/HarbourMasters/2ship2harkinian.git
synced 2024-11-23 05:59:40 +00:00
Fix memory leak in OTRMessage_Init (#466)
This commit is contained in:
parent
86b5f10b26
commit
f270156409
@ -488,7 +488,7 @@ extern "C" void InitOTR() {
|
||||
DebugConsole_Init();
|
||||
|
||||
clearMtx = (uintptr_t)&gMtxClear;
|
||||
// OTRMessage_Init();
|
||||
OTRMessage_Init();
|
||||
OTRAudio_Init();
|
||||
// OTRExtScanner();
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include "2s2h/resource/type/TextMM.h"
|
||||
#include <message_data_static.h>
|
||||
|
||||
// extern "C" MessageTableEntry* sNesMessageEntryTablePtr;
|
||||
// extern "C" MessageTableEntry* sStaffMessageEntryTablePtr;
|
||||
extern "C" MessageTableEntry* sMessageTableNES;
|
||||
extern "C" MessageTableEntry* sMessageTableCredits;
|
||||
|
||||
MessageTableEntry* OTRMessage_LoadTable(const char* filePath, bool isNES) {
|
||||
auto file = std::static_pointer_cast<SOH::TextMM>(
|
||||
@ -51,27 +51,17 @@ MessageTableEntry* OTRMessage_LoadTable(const char* filePath, bool isNES) {
|
||||
return table;
|
||||
}
|
||||
|
||||
extern "C" void OTRMessage_Init(PlayState* play) {
|
||||
// OTRTODO: Added a lot of null checks here so that we don't malloc the table multiple times causing a memory leak.
|
||||
// We really ought to fix the implementation such that we aren't malloc'ing new tables.
|
||||
// Once we fix the implementation, remove these NULL checks.
|
||||
// if (play->msgCtx.messageEntryTableNes == NULL) {
|
||||
play->msgCtx.messageEntryTableNes = OTRMessage_LoadTable("text/message_data_static/message_data_static", true);
|
||||
play->msgCtx.messageEntryTable = play->msgCtx.messageEntryTableNes;
|
||||
//}
|
||||
extern "C" void OTRMessage_Init() {
|
||||
sMessageTableNES = OTRMessage_LoadTable("text/message_data_static/message_data_static", true);
|
||||
|
||||
// if (play->msgCtx.messageTableStaff == NULL) {
|
||||
auto file2 = std::static_pointer_cast<SOH::TextMM>(Ship::Context::GetInstance()->GetResourceManager()->LoadResource(
|
||||
"text/staff_message_data_static/staff_message_data_static"));
|
||||
// OTRTODO: Should not be malloc'ing here. It's fine for now since we check that the message table is already null.
|
||||
play->msgCtx.messageTableStaff = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file2->messages.size());
|
||||
sMessageTableCredits = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file2->messages.size());
|
||||
|
||||
for (size_t i = 0; i < file2->messages.size(); i++) {
|
||||
play->msgCtx.messageTableStaff[i].textId = file2->messages[i].id;
|
||||
play->msgCtx.messageTableStaff[i].typePos =
|
||||
(file2->messages[i].textboxType << 4) | file2->messages[i].textboxYPos;
|
||||
play->msgCtx.messageTableStaff[i].segment = file2->messages[i].msg.c_str();
|
||||
play->msgCtx.messageTableStaff[i].msgSize = file2->messages[i].msg.size();
|
||||
sMessageTableCredits[i].textId = file2->messages[i].id;
|
||||
sMessageTableCredits[i].typePos = (file2->messages[i].textboxType << 4) | file2->messages[i].textboxYPos;
|
||||
sMessageTableCredits[i].segment = file2->messages[i].msg.c_str();
|
||||
sMessageTableCredits[i].msgSize = file2->messages[i].msg.size();
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
@ -205,9 +205,8 @@ u16 gBombersNotebookWeekEventFlags[BOMBERS_NOTEBOOK_EVENT_MAX] = {
|
||||
#undef DEFINE_PERSON
|
||||
#undef DEFINE_EVENT
|
||||
|
||||
// TODO: Scripts
|
||||
// Include message tables D_801C6B98 and D_801CFB08
|
||||
#include "src/code/z_message_tables.inc"
|
||||
MessageTableEntry* sMessageTableNES;
|
||||
MessageTableEntry* sMessageTableCredits;
|
||||
|
||||
s16 D_801CFC78[TEXTBOX_TYPE_MAX] = {
|
||||
0, // TEXTBOX_TYPE_0
|
||||
@ -6216,9 +6215,8 @@ void Message_Update(PlayState* play) {
|
||||
}
|
||||
|
||||
void Message_SetTables(PlayState* play) {
|
||||
// play->msgCtx.messageEntryTableNes = D_801C6B98;
|
||||
// play->msgCtx.messageTableStaff = D_801CFB08;
|
||||
OTRMessage_Init(play);
|
||||
play->msgCtx.messageEntryTableNes = sMessageTableNES;
|
||||
play->msgCtx.messageTableStaff = sMessageTableCredits;
|
||||
}
|
||||
|
||||
void Message_Init(PlayState* play) {
|
||||
|
Loading…
Reference in New Issue
Block a user