Browse Source

Fix massive memory leak

pull/17/head
Anders Jenbo 7 years ago
parent
commit
44ebbafc90
  1. 92
      Stub/init.cpp
  2. 1
      Stub/miniwin_sdl.h
  3. 33
      Stub/sdlrender.cpp

92
Stub/init.cpp

@ -19,6 +19,7 @@ char HeroUndecidedName[17] = { 0 };
bool StartNewGame;
bool CreateSinglePlayerChar;
int HeroChosen = 0;
int menu = 0;
/**
* Case insensitive search for a file name in a directory.
@ -141,9 +142,24 @@ void HideCursor()
SDL_SetCursor(g_cursor);
}
void SetMenu(int MenuId)
{
void *tmp = pPcxTitleImage;
pPcxTitleImage = NULL;
mem_free_dbg(tmp);
TitleImageLoaded = false;
menu = MenuId;
}
void ExitDiablo()
{
printf("Exiting Diablo\n");
SDL_Quit();
exit(0);
}
void SDL_Diablo_UI() // I anticipate to move this later.
{
DWORD dwData[2];
// WNDPROC saveProc;
snd_init(0);
@ -153,7 +169,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
signed int NewHeroNameIndex = 0;
int menu = 0;
SetMenu(0);
SDL_Event event;
int x, y;
bool quit = false;
@ -174,21 +190,15 @@ void SDL_Diablo_UI() // I anticipate to move this later.
// static std::deque<MSG> message_queue;
while (1 && quit == false) {
while (!quit) {
DrawMouse();
PaletteFadeIn(32);
if (menu == 0) {
LoadArtWithPal("ui_art\\mainmenu.pcx", &pPcxTitleImage, 1, dwData);
gdwTitleWidth = dwData[0];
gdwTitleHeight = dwData[1];
SDL_RenderDiabloMainPage();
}
if (menu == 2) {
LoadArtWithPal("ui_art\\selhero.pcx", &pPcxTitleImage, 1, dwData);
gdwTitleWidth = dwData[0];
gdwTitleHeight = dwData[1];
if (CharsLoaded == 0) {
LoadCharNamesintoMemory(0, 7);
// LoadHeroStats();
@ -196,25 +206,19 @@ void SDL_Diablo_UI() // I anticipate to move this later.
}
SDL_RenderDiabloSinglePlayerPage();
gbMaxPlayers = 1;
// DrawMouse(); // Not accurate for some reason. It adds too much and I am not sure why.
DrawMouse();
ConstantButtons();
}
if (menu == 3) {
LoadArtWithPal("ui_art\\selhero.pcx", &pPcxTitleImage, 1, dwData);
gdwTitleWidth = dwData[0];
gdwTitleHeight = dwData[1];
CreateHeroMenu();
DrawNewHeroKartinka(HeroPortrait, 1);
ConstantButtons();
// DrawMouse();
DrawMouse();
}
int m4Loaded = 0;
if (menu == 4) {
LoadArtWithPal("ui_art\\selhero.pcx", &pPcxTitleImage, 1, dwData);
gdwTitleWidth = dwData[0];
gdwTitleHeight = dwData[1];
DrawNewHeroKartinka(HeroPortrait, 0);
RenderDefaultStats(HeroPortrait);
RenderUndecidedHeroName();
@ -222,18 +226,12 @@ void SDL_Diablo_UI() // I anticipate to move this later.
DrawMouse();
}
if (menu == 5) {
LoadArtWithPal("ui_art\\selhero.pcx", &pPcxTitleImage, 1, dwData);
gdwTitleWidth = dwData[0];
gdwTitleHeight = dwData[1];
DrawPreGameOptions(HeroPortrait, 1);
RenderDefaultStats(HeroPortrait);
ConstantButtons();
DrawMouse();
}
if (menu == 6) {
LoadArtWithPal("ui_art\\selhero.pcx", &pPcxTitleImage, 1, dwData);
gdwTitleWidth = dwData[0];
gdwTitleHeight = dwData[1];
DrawPreGameDifficultySelection(HeroPortrait, 1);
RenderDefaultStats(HeroPortrait);
ConstantButtons();
@ -241,9 +239,6 @@ void SDL_Diablo_UI() // I anticipate to move this later.
}
if (menu == 10) {
LoadArtWithPal("ui_art\\credits.pcx", &pPcxTitleImage, 1, dwData);
gdwTitleWidth = dwData[0];
gdwTitleHeight = dwData[1];
ShowCredts();
}
@ -253,8 +248,11 @@ void SDL_Diablo_UI() // I anticipate to move this later.
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
if (menu != 0) {
menu = 0;
SetMenu(0);
break;
}
quit = true;
ExitDiablo();
break;
case SDLK_BACKSPACE:
@ -286,10 +284,8 @@ void SDL_Diablo_UI() // I anticipate to move this later.
}
if (event.type == SDL_QUIT) {
quit = true;
SDL_Quit();
exit(0); // SDL quit doesn't always work.
ExitDiablo();
}
if (event.type == SDL_MOUSEMOTION) {
@ -315,7 +311,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
if ((x > ClickListStart) && (y > ClickListStart) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + sizeOfBox)) { // Single clicked
printf("SinglePlayer Diablo\n");
menu = 2;
SetMenu(2);
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox) + sizeOfBox)) { // MultiBox clicked
@ -323,13 +319,11 @@ void SDL_Diablo_UI() // I anticipate to move this later.
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 2)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 2) + sizeOfBox)) { // Reply Intro clicked
printf("Credits\n");
menu = 10;
SetMenu(10);
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 4)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 4) + sizeOfBox)) { // ShowCredits clicked
printf("Exiting Diablo\n");
quit = true;
SDL_Quit();
exit(0);
ExitDiablo();
}
} // End of this Menu0
@ -355,7 +349,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
if (TotalPlayers >= 1 && (x > ClickListStart) && (y > ClickListStart) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + sizeOfBox)) { // MultiBox clicked
strcpy(chr_name_str, hero_names[0]);
printf("Player %s\n", chr_name_str);
menu = 5;
SetMenu(5);
// break;
}
@ -363,7 +357,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
printf("Player 2 Diablo\n");
strcpy(chr_name_str, hero_names[1]);
printf("Player %s\n", chr_name_str);
menu = 5;
SetMenu(5);
// break;
}
@ -371,7 +365,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
printf("Player 3 Diablo\n");
strcpy(chr_name_str, hero_names[2]);
printf("Player %s\n", chr_name_str);
menu = 5;
SetMenu(5);
// break;
}
@ -380,7 +374,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
effects_play_sound("Sfx\\Items\\Titlslct.wav");
strcpy(chr_name_str, hero_names[3]);
printf("Player %s\n", chr_name_str);
menu = 5;
SetMenu(5);
// break;
}
@ -389,7 +383,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
effects_play_sound("Sfx\\Items\\Titlslct.wav");
strcpy(chr_name_str, hero_names[4]);
printf("Player %s\n", chr_name_str);
menu = 5;
SetMenu(5);
// break;
}
@ -398,7 +392,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
effects_play_sound("Sfx\\Items\\Titlslct.wav");
strcpy(chr_name_str, hero_names[5]);
printf("Player %s\n", chr_name_str);
menu = 5;
SetMenu(5);
// break;
}
@ -406,11 +400,11 @@ void SDL_Diablo_UI() // I anticipate to move this later.
HeroPortrait = 3;
printf("Cancel\n\n\n");
menu = 0;
SetMenu(0);
}
if ((x > CreateHeroX) && (y > CreateHeroY) && (x < CreateHeroX + WidthOfBox) && (y < CreateHeroY + sizeOfBox)) {
printf("Clicked Create Hero Box\n");
menu = 3;
SetMenu(3);
}
}
if (menu == 3) {
@ -464,20 +458,20 @@ void SDL_Diablo_UI() // I anticipate to move this later.
printf(" warrior I was hit\n\n\n");
HeroPortrait = 0;
HeroChosen = 0;
menu = 4;
SetMenu(4);
}
if ((x > RogueSelectBox.x) && (y > RogueSelectBox.y) && (x < RogueSelectBox.w) && (y < RogueSelectBox.h)) {
printf(" rogue I was hit\n\n\n");
HeroPortrait = 1;
HeroChosen = 1;
menu = 4;
SetMenu(4);
}
if ((x > SorcerorSelectBox.x) && (y > SorcerorSelectBox.y) && (x < SorcerorSelectBox.w) && (y < SorcerorSelectBox.h)) {
HeroPortrait = 2;
printf("sorceror I was hit\n\n\n");
HeroChosen = 2;
menu = 4;
SetMenu(4);
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
@ -509,7 +503,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
printf("Cancel\n\n\n");
HeroPortrait = 3;
menu = 3;
SetMenu(3);
}
if ((x > ClickOkBox.x) && (y > ClickOkBox.y) && (x < ClickOkBox.w) && (y < ClickOkBox.h)) {
@ -571,7 +565,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
if (cpu_time_used > 0.5 && (x > NewGameBox.x) && (y > NewGameBox.y) && (x < NewGameBox.w) && (y < NewGameBox.h)) {
printf(" New Game I was hit\n\n\n");
menu = 6;
SetMenu(6);
cpu_time_used = 0;
timestart = 0;
start = 0;
@ -592,7 +586,7 @@ void SDL_Diablo_UI() // I anticipate to move this later.
printf("Cancel\n\n\n");
menu = 2; // Return back to select hero menu.
SetMenu(2); // Return back to select hero menu.
}
}

1
Stub/miniwin_sdl.h

@ -18,6 +18,7 @@ extern SDL_Surface *surface;
extern SDL_Palette *palette;
extern SDL_Surface *pal_surface;
extern bool TitleImageLoaded;
void sdl_present_surface();

33
Stub/sdlrender.cpp

@ -33,6 +33,7 @@ SDL_Event input;
bool SinglePlayerMenuItemsLoaded = 0;
bool DiabloImageLoaded = 0;
bool DiabloMainMenuListLoaded = 0;
bool TitleImageLoaded = false;
_uiheroinfo heroarray[10];
@ -68,7 +69,8 @@ int gb_Lfont_str_len;
int gb_Lfont_pix_width;
int the_pcx_frame;
char *the_long_credits[] = { "",
char *the_long_credits[] = {
"",
"",
"",
"",
@ -553,7 +555,8 @@ char *the_long_credits[] = { "",
" ",
" ",
" ",
NULL };
NULL
};
int creditline = 0;
int ybase = 0;
@ -740,8 +743,23 @@ int __fastcall GetPCXFontWidth(char *str, BYTE *font)
return len;
}
void LoadTitelArt(char *pszFile)
{
DWORD dwData[2];
if (TitleImageLoaded) {
return;
}
LoadArtWithPal(pszFile, &pPcxTitleImage, 1, dwData);
gdwTitleWidth = dwData[0];
gdwTitleHeight = dwData[1];
TitleImageLoaded = true;
}
void ShowCredts()
{
LoadTitelArt("ui_art\\credits.pcx");
ybase += 1;
if (ybase >= pFont16[1]) {
ybase = 0;
@ -782,7 +800,7 @@ void RenderDiabloLogo()
MyPcxFRAME = 1;
}
DrawArtWithMask(320 - (gdwLogoWidth / 2), 0, gdwLogoWidth, gdwLogoHeight, MyPcxFRAME, 250, pPcxLogoImage);
DrawArtWithMask(GetCenter(gdwLogoWidth), 0, gdwLogoWidth, gdwLogoHeight, MyPcxFRAME, 250, pPcxLogoImage);
}
void DrawCursor(int mx, int my)
@ -818,6 +836,11 @@ void DrawMouse()
void SDL_RenderDiabloMainPage()
{
char *pszFile = "ui_art\\mainmenu.pcx";
if (false) //DiabloUI_GetSpawned()
pszFile = "ui_art\\swmmenu.pcx";
LoadTitelArt(pszFile);
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
int totalPentFrames = 8;
@ -864,6 +887,7 @@ void SDL_RenderDiabloMainPage()
void SDL_RenderDiabloSinglePlayerPage()
{
LoadTitelArt("ui_art\\selhero.pcx");
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
RenderDiabloLogo();
RenderCharNames();
@ -922,6 +946,7 @@ int TotalPlayers = 0;
void DrawNewHeroKartinka(int image, int ShowClasses)
{
LoadTitelArt("ui_art\\selhero.pcx");
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
RenderDiabloLogo();
@ -943,6 +968,7 @@ void DrawNewHeroKartinka(int image, int ShowClasses)
void DrawPreGameOptions(int image, int ShowClasses)
{
LoadTitelArt("ui_art\\selhero.pcx");
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
RenderDiabloLogo();
@ -963,6 +989,7 @@ void DrawPreGameOptions(int image, int ShowClasses)
void DrawPreGameDifficultySelection(int image, int ShowClasses)
{
LoadTitelArt("ui_art\\selhero.pcx");
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
RenderDiabloLogo();

Loading…
Cancel
Save