More modern memory management in the modern pstarmap file.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user