fix memory leaks, avoid invalidate texture (#207)

* Fixed macos

* More stupid fixes

* update with main and update torch and lus and enable action on this branch

* Update FrameInterpolation.h

* Update FrameInterpolation.cpp

* fix some memory leak

* Update torch

* Update torch

* update torch and lus

* reduce texture import

* don't use fork of torch and lus

* Update torch

* Update torch

---------

Co-authored-by: Lywx <kiritodev01@gmail.com>
This commit is contained in:
coco875
2025-05-23 22:49:06 +00:00
committed by GitHub
parent af4535c3c5
commit 9363e3d776
20 changed files with 130 additions and 29 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ name: GenerateBuilds
on:
push:
branches: ["main"]
branches: ["*"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
+4 -4
View File
@@ -34,15 +34,15 @@ Light D_800E8688 = { {
s16 D_8018EDB0;
s16 D_8018EDB2;
s16 D_8018EDB4;
Vtx* D_8018EDB8;
Vtx* D_8018EDBC;
Vtx D_8018EDB8[480];
Vtx D_8018EDBC[480];
/*** utils **/
#define SQ(x) ((x) * (x))
void func_800AF9B0(void) {
D_8018EDB8 = (void*) calloc(480, sizeof(Vtx));
D_8018EDBC = (void*) calloc(480, sizeof(Vtx));
// D_8018EDB8 = (void*) calloc(480, sizeof(Vtx));
// D_8018EDBC = (void*) calloc(480, sizeof(Vtx));
}
// could be a normal vertex, not a color...
+3
View File
@@ -22,6 +22,9 @@ extern "C" {
}
World::World() {}
World::~World() {
CM_CleanWorld();
}
Course* CurrentCourse;
Cup* CurrentCup;
+1
View File
@@ -52,6 +52,7 @@ class World {
public:
explicit World();
~World();
void AddCourse(Course* course);
+15 -4
View File
@@ -30,6 +30,11 @@ namespace Editor {
Editor::Editor() {
}
Editor::~Editor() {
ClearObjects();
ClearMatrixPool();
}
void Editor::Load() {
printf("Editor: Loading Editor...\n");
eObjectPicker.Load();
@@ -58,10 +63,16 @@ namespace Editor {
Ship::Coords mousePos = wnd->GetMousePos();
bool isMouseDown = wnd->GetMouseState(Ship::LUS_MOUSE_BTN_LEFT);
eGameObjects.erase(
std::remove_if(eGameObjects.begin(), eGameObjects.end(),
[](const auto& object) { return (*object->DespawnFlag) == object->DespawnValue; }),
eGameObjects.end());
auto it = std::remove_if(eGameObjects.begin(), eGameObjects.end(),
[](auto& object) {
if (*object->DespawnFlag == object->DespawnValue) {
delete object; // Free the pointed-to memory
return true; // Remove the pointer from the vector
}
return false;
});
eGameObjects.erase(it, eGameObjects.end());
if (isMouseDown && !wasMouseDown) {
// Mouse just pressed (Pressed state)
+1
View File
@@ -14,6 +14,7 @@ namespace Editor {
class Editor {
public:
Editor();
~Editor();
ObjectPicker eObjectPicker;
std::vector<GameObject*> eGameObjects;
+2 -2
View File
@@ -352,8 +352,8 @@ bool IntersectRaySphere(const Ray& ray, const FVector& sphereCenter, float radiu
// Transform a matrix to a matrix identity
void Editor_MatrixIdentity(Mat4 mtx) {
register s32 i;
register s32 k;
s32 i;
s32 k;
for (i = 0; i < 4; i++) {
for (k = 0; k < 4; k++) {
+6 -1
View File
@@ -298,6 +298,9 @@ void GameEngine::Destroy() {
#ifdef __SWITCH__
Ship::Switch::Exit();
#endif
GameUI::Destroy();
delete GameEngine::Instance;
GameEngine::Instance = nullptr;
}
bool ShouldClearTextureCacheAtEndOfFrame = false;
@@ -509,7 +512,9 @@ ImFont* GameEngine::CreateFontWithSize(float size, std::string fontPath) {
initData->Path = fontPath;
std::shared_ptr<Ship::Font> fontData = std::static_pointer_cast<Ship::Font>(
Ship::Context::GetInstance()->GetResourceManager()->LoadResource(fontPath, false, initData));
font = mImGuiIo->Fonts->AddFontFromMemoryTTF(fontData->Data, fontData->DataSize, size);
char* fontDataPtr = (char*)malloc(fontData->DataSize);
memcpy(fontDataPtr, fontData->Data, fontData->DataSize);
font = mImGuiIo->Fonts->AddFontFromMemoryTTF(fontDataPtr, fontData->DataSize, size);
}
// FontAwesome fonts need to have their sizes reduced by 2.0f/3.0f in order to align correctly
float iconFontSize = size * 2.0f / 3.0f;
+33
View File
@@ -198,6 +198,38 @@ void CustomEngineInit() {
// gModelLoader.Load();
}
void CustomEngineDestroy() {
delete gMarioRaceway;
delete gChocoMountain;
delete gBowsersCastle;
delete gBansheeBoardwalk;
delete gYoshiValley;
delete gFrappeSnowland;
delete gKoopaTroopaBeach;
delete gRoyalRaceway;
delete gLuigiRaceway;
delete gMooMooFarm;
delete gToadsTurnpike;
delete gKalimariDesert;
delete gSherbetLand;
delete gRainbowRoad;
delete gWarioStadium;
delete gBlockFort;
delete gSkyscraper;
delete gDoubleDeck;
delete gDkJungle;
delete gBigDonut;
delete gPodiumCeremony;
delete gHarbour;
delete gTestCourse;
delete gMushroomCup;
delete gFlowerCup;
delete gStarCup;
delete gSpecialCup;
delete gBattleCup;
}
extern "C" {
void HM_InitIntro() {
@@ -873,6 +905,7 @@ extern "C"
while (WindowIsRunning()) {
push_frame();
}
CustomEngineDestroy();
// GameEngine::Instance->ProcessFrame(push_frame);
GameEngine::Instance->Destroy();
return 0;
+1 -1
View File
@@ -12,7 +12,7 @@
#include <SDL_hints.h>
#include <SDL_video.h>
#include "graphic/Fast3D/gfx_metal.h"
#include "graphic/Fast3D/backends/gfx_metal.h"
#include <imgui_impl_metal.h>
#include <imgui_impl_sdl2.h>
#else
@@ -52,6 +52,11 @@ static bool invert_matrix(const float m[16], float invOut[16]);
using namespace std;
extern "C" {
extern Mat4* gInterpolationMatrix;
void mtxf_translate(Mat4, Vec3f);
}
namespace {
enum class Op {
+1 -1
View File
@@ -19,7 +19,7 @@ extern "C" {
#define TAG_ITEM_ADDR(x) ((u32) 0x10000000 | (u32)x)
#define TAG_SMOKE_DUST(x) ((u32) 0x20000000 | (u32) (x))
#define TAG_LETTER(x) ((u32)0x30000000 | (u32) (x))
#define TAG_OBJECT(x) ((u32)0x40000000 | (u32)(x))
#define TAG_OBJECT(x) ((u32)0x40000000 | (u32) (uintptr_t) (x))
void FrameInterpolation_ShouldInterpolateFrame(bool shouldInterpolate);
@@ -21,6 +21,7 @@ SM64::AudioBankFactoryV0::ReadResource(std::shared_ptr<Ship::File> file,
auto* instrument = new Instrument();
bool valid = reader->ReadUByte();
if(!valid){
delete instrument;
bank->instruments.push_back(nullptr);
continue;
}
+17
View File
@@ -8,4 +8,21 @@ CtlEntry* AudioBank::GetPointer() {
size_t AudioBank::GetPointerSize() {
return sizeof(mData);
}
AudioBank::~AudioBank() {
for (auto& instrument : instruments) {
if (instrument != nullptr) {
if (instrument->envelope != nullptr) {
delete[] instrument->envelope;
instrument->envelope = nullptr;
}
delete instrument;
}
}
for (auto& drum : drums) {
delete drum;
}
instruments.clear();
drums.clear();
}
}
+1
View File
@@ -47,6 +47,7 @@ class AudioBank : public Ship::Resource<CtlEntry> {
using Resource::Resource;
AudioBank() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {}
~AudioBank() override;
CtlEntry* GetPointer();
size_t GetPointerSize();
+14
View File
@@ -8,4 +8,18 @@ AudioBankSample* AudioSample::GetPointer() {
size_t AudioSample::GetPointerSize() {
return sizeof(mData);
}
AudioSample::~AudioSample() {
if (mData.sampleAddr != nullptr) {
// delete[] mData.sampleAddr;
mData.sampleAddr = nullptr;
}
if (mData.book->book != nullptr) {
delete[] mData.book->book;
mData.book->book = nullptr;
}
if (mData.loop->state != nullptr) {
delete[] mData.loop->state;
mData.loop->state = nullptr;
}
}
}
+1
View File
@@ -34,6 +34,7 @@ class AudioSample : public Ship::Resource<AudioBankSample> {
using Resource::Resource;
AudioSample() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {}
~AudioSample() override;
AudioBankSample* GetPointer();
size_t GetPointerSize();
+21 -13
View File
@@ -48,7 +48,6 @@ s16 gMatrixEffectCount;
s32 D_80164AF4[3];
struct_D_802F1F80* gPlayerPalette;
static const char* sKartUpperTexture;
static const char* sKartLowerTexture;
u16 gPlayerRedEffect[8];
u16 gPlayerGreenEffect[8];
u16 gPlayerBlueEffect[8];
@@ -1600,6 +1599,19 @@ void render_player_shadow_credits(Player* player, s8 playerId, s8 arg2) {
gSPTexture(gDisplayListHead++, 1, 1, 0, G_TX_RENDERTILE, G_OFF);
}
Vtx player_vtx[] = {
{ { { 9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } },
{ { { 9, 0, -6 }, 0, { 4032, 4032 }, { 0xFF, 0xFF, 0xFF, 0xFF } } },
{ { { -9, 18, -6 }, 0, { 0, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } },
{ { { -9, 0, -6 }, 0, { 0, 4032 }, { 0xFF, 0xFF, 0xFF, 0xFF } } },
};
Vtx player_vtx_flip[] = {
{ { { 9, 18, -6 }, 0, { 0, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } },
{ { { 9, 0, -6 }, 0, { 0, 4032 }, { 0xFF, 0xFF, 0xFF, 0xFF } } },
{ { { -9, 18, -6 }, 0, { 4032, 0 }, { 0xFF, 0xFF, 0xFF, 0xFF } } },
{ { { -9, 0, -6 }, 0, { 4032, 4032 }, { 0xFF, 0xFF, 0xFF, 0xFF } } },
};
void render_kart(Player* player, s8 playerId, s8 screenId, s8 arg3) {
UNUSED s32 pad;
Mat4 mtx;
@@ -1727,19 +1739,15 @@ void render_kart(Player* player, s8 playerId, s8 screenId, s8 arg3) {
}
// Render heads
gDPLoadTextureBlock(gDisplayListHead++, sKartUpperTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0,
gDPLoadTextureBlock(gDisplayListHead++, sKartUpperTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 64, 0,
G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD,
G_TX_NOLOD);
gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3], 4, 0);
gSPDisplayList(gDisplayListHead++, common_square_plain_render);
// Render karts
u8* test = (u8*) LOAD_ASSET(sKartUpperTexture);
gDPLoadTextureBlock(gDisplayListHead++, test + 0x7C0, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0,
G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD,
G_TX_NOLOD);
gSPVertex(gDisplayListHead++, &D_800DDBB4[playerId][arg3 + 4], 4, 0);
gSPDisplayList(gDisplayListHead++, common_square_plain_render);
if (arg3 == 0) {
gSPVertex(gDisplayListHead++, player_vtx, 4, 0);
} else {
gSPVertex(gDisplayListHead++, player_vtx_flip, 4, 0);
}
gSP2Triangles(gDisplayListHead++, 0, 1, 2, 0, 1, 3, 2, 0);
gSPTexture(gDisplayListHead++, 1, 1, 0, G_TX_RENDERTILE, G_OFF);
gDPSetAlphaCompare(gDisplayListHead++, G_AC_NONE);
@@ -1964,7 +1972,7 @@ void render_player(Player* player, s8 playerId, s8 screenId) {
func_80025DE8(player, playerId, screenId, var_v1);
}
// Allows wheels to spin
gSPInvalidateTexCache(gDisplayListHead++, sKartLowerTexture);
gSPInvalidateTexCache(gDisplayListHead++, sKartUpperTexture);
}
void func_80026A48(Player* player, s8 arg1) {
+1 -1
Submodule torch updated: 8e56ea0294...f75facb208