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