More modern memory management in the modern pstarmap file.

This commit is contained in:
2024-04-24 20:05:26 -04:00
parent 34199636ed
commit d813c3ae37
+9 -14
View File
@@ -18,6 +18,7 @@
*/
#include <vector>
#include <memory>
#include "../starmap.h"
#include "../menustat.h"
@@ -28,22 +29,14 @@
extern "C" bool
DoStarSearch (MENU_STATE *pMS)
try
{
TEXTENTRY_STATE tes;
STAR_SEARCH_STATE *pss;
bool success;
pss = (STAR_SEARCH_STATE *) HMalloc (sizeof (*pss));
if (!pss)
return FALSE;
auto pss= std::make_unique< STAR_SEARCH_STATE >();
std::vector< int > sorted( GetStarCount() ); // Manages the sorted stars memory.
pss->SortedStars= sorted.data();
if (!pss->SortedStars)
{
HFree (pss);
return FALSE;
}
DrawSISMessageEx ("", 0, 0, DSME_SETFR);
@@ -52,14 +45,14 @@ DoStarSearch (MENU_STATE *pMS)
pss->Text[0] = '\0';
pss->LastText[0] = '\0';
pss->FirstIndex = -1;
SortStarsOnName (pss);
SortStarsOnName (pss.get());
// text entry setup
tes.Initialized = FALSE;
tes.BaseStr = pss->Text;
tes.MaxSize = sizeof (pss->Text);
tes.CursorPos = 0;
tes.CbParam = pss;
tes.CbParam = pss.get();
tes.ChangeCallback = OnStarNameChange;
tes.FrameCallback = OnStarNameFrame;
@@ -69,7 +62,9 @@ DoStarSearch (MENU_STATE *pMS)
DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR);
HFree (pss);
return success;
}
catch( const std::bad_alloc & )
{
return FALSE;
}