Skip to content

Commit

Permalink
Merge pull request JACoders#1056 from z33ky/fix-crashes
Browse files Browse the repository at this point in the history
Fix singleplayer crashes
  • Loading branch information
xycaleth authored Nov 15, 2020
2 parents ffed938 + 1e928d6 commit e64bbb5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
21 changes: 7 additions & 14 deletions code/cgame/cg_credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,13 @@ static const char *GetSubString(std::string &strResult)

// sort entries by their last name (starts at back of string and moves forward until start or just before whitespace)
// ...
static int SortBySurname(const void *elem1, const void *elem2)
static bool SortBySurname(const StringAndSize_t &str1, const StringAndSize_t &str2)
{
StringAndSize_t *p1 = (StringAndSize_t *) elem1;
StringAndSize_t *p2 = (StringAndSize_t *) elem2;
std::string::const_reverse_iterator rstart1 = std::find_if(str1.str.rbegin(), str1.str.rend(), isspace);
std::string::const_reverse_iterator rstart2 = std::find_if(str2.str.rbegin(), str2.str.rend(), isspace);


const char *psSurName1 = p1->c_str() + (strlen(p1->c_str())-1);
const char *psSurName2 = p2->c_str() + (strlen(p2->c_str())-1);

while (psSurName1 > p1->c_str() && !isspace(*psSurName1)) psSurName1--;
while (psSurName2 > p2->c_str() && !isspace(*psSurName2)) psSurName2--;
if (isspace(*psSurName1)) psSurName1++;
if (isspace(*psSurName2)) psSurName2++;

return Q_stricmp(psSurName1, psSurName2);
return Q_stricmp(&*rstart1.base(), &*rstart2.base()) < 0;
}


Expand Down Expand Up @@ -442,7 +435,7 @@ void CG_Credits_Init( const char *psStripReference, vec4_t *pv4Color)
{
// sort entries RHS dotted entries by alpha...
//
qsort(&CreditLine.vstrText[0], CreditLine.vstrText.size(), sizeof(CreditLine.vstrText[0]), SortBySurname);
std::sort( CreditLine.vstrText.begin(), CreditLine.vstrText.end(), SortBySurname );

CreditData.CreditLines.push_back( CreditLine );
iLineNumber += CreditLine.vstrText.size();
Expand Down Expand Up @@ -485,7 +478,7 @@ void CG_Credits_Init( const char *psStripReference, vec4_t *pv4Color)
{
// sort entries by alpha...
//
qsort(&CreditCard.vstrText[0], CreditCard.vstrText.size(), sizeof(CreditCard.vstrText[0]), SortBySurname);
std::sort( CreditCard.vstrText.begin(), CreditCard.vstrText.end(), SortBySurname );

CreditData.CreditCards.push_back(CreditCard);
}
Expand Down
4 changes: 4 additions & 0 deletions code/rd-vanilla/tr_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,10 @@ static void RB_SurfaceLathe()
{
lod = 4;
}
if ( lod < 1 )
{
lod = 1;
}
bezierStep = BEZIER_STEP * lod;
latheStep = LATHE_SEG_STEP * lod;

Expand Down
23 changes: 8 additions & 15 deletions codeJK2/cgame/cg_credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,13 @@ static const char *GetSubString(std::string &strResult)

// sort entries by their last name (starts at back of string and moves forward until start or just before whitespace)
// ...
static int SortBySurname(const void *elem1, const void *elem2)
static bool SortBySurname(const StringAndSize_t &str1, const StringAndSize_t &str2)
{
StringAndSize_t *p1 = (StringAndSize_t *) elem1;
StringAndSize_t *p2 = (StringAndSize_t *) elem2;

const char *psSurName1 = p1->c_str() + (strlen( p1->c_str() ) - 1);
const char *psSurName2 = p2->c_str() + (strlen( p2->c_str() ) - 1);

while (psSurName1 > p1->c_str() && !isspace(*psSurName1)) psSurName1--;
while (psSurName2 > p2->c_str() && !isspace(*psSurName2)) psSurName2--;
if (isspace(*psSurName1)) psSurName1++;
if (isspace(*psSurName2)) psSurName2++;

return Q_stricmp(psSurName1, psSurName2);
std::string::const_reverse_iterator rstart1 = std::find_if(str1.str.rbegin(), str1.str.rend(), isspace);
std::string::const_reverse_iterator rstart2 = std::find_if(str2.str.rbegin(), str2.str.rend(), isspace);


return Q_stricmp(&*rstart1.base(), &*rstart2.base()) < 0;
}


Expand Down Expand Up @@ -424,7 +417,7 @@ void CG_Credits_Init( const char *psStripReference, vec4_t *pv4Color )
{
// sort entries RHS dotted entries by alpha...
//
qsort(&CreditLine.vstrText[0], CreditLine.vstrText.size(), sizeof(CreditLine.vstrText[0]), SortBySurname);
std::sort( CreditLine.vstrText.begin(), CreditLine.vstrText.end(), SortBySurname );

CreditData.CreditLines.push_back( CreditLine );
iLineNumber += CreditLine.vstrText.size();
Expand Down Expand Up @@ -467,7 +460,7 @@ void CG_Credits_Init( const char *psStripReference, vec4_t *pv4Color )
{
// sort entries by alpha...
//
qsort(&CreditCard.vstrText[0], CreditCard.vstrText.size(), sizeof(CreditCard.vstrText[0]), SortBySurname);
std::sort( CreditCard.vstrText.begin(), CreditCard.vstrText.end(), SortBySurname );

CreditData.CreditCards.push_back(CreditCard);
}
Expand Down

0 comments on commit e64bbb5

Please sign in to comment.