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

33
Stub/sdlrender.cpp

@ -33,6 +33,7 @@ SDL_Event input;
bool SinglePlayerMenuItemsLoaded = 0; bool SinglePlayerMenuItemsLoaded = 0;
bool DiabloImageLoaded = 0; bool DiabloImageLoaded = 0;
bool DiabloMainMenuListLoaded = 0; bool DiabloMainMenuListLoaded = 0;
bool TitleImageLoaded = false;
_uiheroinfo heroarray[10]; _uiheroinfo heroarray[10];
@ -68,7 +69,8 @@ int gb_Lfont_str_len;
int gb_Lfont_pix_width; int gb_Lfont_pix_width;
int the_pcx_frame; 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 creditline = 0;
int ybase = 0; int ybase = 0;
@ -740,8 +743,23 @@ int __fastcall GetPCXFontWidth(char *str, BYTE *font)
return len; 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() void ShowCredts()
{ {
LoadTitelArt("ui_art\\credits.pcx");
ybase += 1; ybase += 1;
if (ybase >= pFont16[1]) { if (ybase >= pFont16[1]) {
ybase = 0; ybase = 0;
@ -782,7 +800,7 @@ void RenderDiabloLogo()
MyPcxFRAME = 1; 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) void DrawCursor(int mx, int my)
@ -818,6 +836,11 @@ void DrawMouse()
void SDL_RenderDiabloMainPage() 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); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
int totalPentFrames = 8; int totalPentFrames = 8;
@ -864,6 +887,7 @@ void SDL_RenderDiabloMainPage()
void SDL_RenderDiabloSinglePlayerPage() void SDL_RenderDiabloSinglePlayerPage()
{ {
LoadTitelArt("ui_art\\selhero.pcx");
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
RenderDiabloLogo(); RenderDiabloLogo();
RenderCharNames(); RenderCharNames();
@ -922,6 +946,7 @@ int TotalPlayers = 0;
void DrawNewHeroKartinka(int image, int ShowClasses) void DrawNewHeroKartinka(int image, int ShowClasses)
{ {
LoadTitelArt("ui_art\\selhero.pcx");
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
RenderDiabloLogo(); RenderDiabloLogo();
@ -943,6 +968,7 @@ void DrawNewHeroKartinka(int image, int ShowClasses)
void DrawPreGameOptions(int image, int ShowClasses) void DrawPreGameOptions(int image, int ShowClasses)
{ {
LoadTitelArt("ui_art\\selhero.pcx");
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
RenderDiabloLogo(); RenderDiabloLogo();
@ -963,6 +989,7 @@ void DrawPreGameOptions(int image, int ShowClasses)
void DrawPreGameDifficultySelection(int image, int ShowClasses) void DrawPreGameDifficultySelection(int image, int ShowClasses)
{ {
LoadTitelArt("ui_art\\selhero.pcx");
DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage); DrawArtImage(0, 0, gdwTitleWidth, gdwTitleHeight, 0, pPcxTitleImage);
RenderDiabloLogo(); RenderDiabloLogo();

Loading…
Cancel
Save