Skip to content

[GEN][ZH] Demote throw to assert in InGameUI::message, InGameUI::messageColor #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void AsciiString::format_va(const char* format, va_list args)
}
else
{
DEBUG_ASSERTCRASH(false, ("AsciiString::format_va failed with code:%d format:\"%s\"", result, format));
DEBUG_CRASH(("AsciiString::format_va failed with code:%d format:\"%s\"", result, format));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void UnicodeString::format_va(const WideChar* format, va_list args)
}
else
{
DEBUG_ASSERTCRASH(false, ("UnicodeString::format_va failed with code:%d", result));
DEBUG_CRASH(("UnicodeString::format_va failed with code:%d", result));
}
}

Expand Down
62 changes: 38 additions & 24 deletions Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1968,16 +1968,21 @@ void InGameUI::message( AsciiString stringManagerLabel, ... )

// construct the final text after formatting
va_list args;
va_start( args, stringManagerLabel );
va_start( args, stringManagerLabel );
WideChar buf[ UnicodeString::MAX_FORMAT_BUF_LEN ];
if( _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, stringManagerString.str(), args ) < 0 )
throw ERROR_OUT_OF_MEMORY;
formattedMessage.set( buf );
va_end(args);

// add the text to the ui
addMessageText( formattedMessage );
int result = _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, stringManagerString.str(), args );
va_end(args);

if( result >= 0 )
{
formattedMessage.set( buf );
// add the text to the ui
addMessageText( formattedMessage );
}
else
{
DEBUG_CRASH(("InGameUI::message failed with code:%d", result));
}
} // end

//-------------------------------------------------------------------------------------------------
Expand All @@ -1990,16 +1995,21 @@ void InGameUI::message( UnicodeString format, ... )

// construct the final text after formatting
va_list args;
va_start( args, format );
va_start( args, format );
WideChar buf[ UnicodeString::MAX_FORMAT_BUF_LEN ];
if( _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, format.str(), args ) < 0 )
throw ERROR_OUT_OF_MEMORY;
formattedMessage.set( buf );
va_end(args);

// add the text to the ui
addMessageText( formattedMessage );
int result = _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, format.str(), args );
va_end(args);

if( result >= 0 )
{
formattedMessage.set( buf );
// add the text to the ui
addMessageText( formattedMessage );
}
else
{
DEBUG_CRASH(("InGameUI::message failed with code:%d", result));
}
} // end message

//-------------------------------------------------------------------------------------------------
Expand All @@ -2012,16 +2022,20 @@ void InGameUI::messageColor( const RGBColor *rgbColor, UnicodeString format, ...

// construct the final text after formatting
va_list args;
va_start( args, format );
va_start( args, format );
WideChar buf[ UnicodeString::MAX_FORMAT_BUF_LEN ];
if( _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, format.str(), args ) < 0 )
throw ERROR_OUT_OF_MEMORY;
formattedMessage.set( buf );
va_end(args);

// add the text to the ui
addMessageText( formattedMessage, rgbColor );
int result = _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, format.str(), args );
Copy link
Author

@xezon xezon May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A mistake creeped in here. va_end(args) was lost by mistake. I will fix in follow up. #872


if( result >= 0 )
{
formattedMessage.set( buf );
// add the text to the ui
addMessageText( formattedMessage, rgbColor );
}
else
{
DEBUG_CRASH(("InGameUI::messageColor failed with code:%d", result));
}
} // end message

//-------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void AsciiString::format_va(const char* format, va_list args)
}
else
{
DEBUG_ASSERTCRASH(false, ("AsciiString::format_va failed with code:%d format:\"%s\"", result, format));
DEBUG_CRASH(("AsciiString::format_va failed with code:%d format:\"%s\"", result, format));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void UnicodeString::format_va(const WideChar* format, va_list args)
}
else
{
DEBUG_ASSERTCRASH(false, ("UnicodeString::format_va failed with code:%d", result));
DEBUG_CRASH(("UnicodeString::format_va failed with code:%d", result));
}
}

Expand Down
62 changes: 38 additions & 24 deletions GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2024,16 +2024,21 @@ void InGameUI::message( AsciiString stringManagerLabel, ... )

// construct the final text after formatting
va_list args;
va_start( args, stringManagerLabel );
va_start( args, stringManagerLabel );
WideChar buf[ UnicodeString::MAX_FORMAT_BUF_LEN ];
if( _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, stringManagerString.str(), args ) < 0 )
throw ERROR_OUT_OF_MEMORY;
formattedMessage.set( buf );
va_end(args);

// add the text to the ui
addMessageText( formattedMessage );
int result = _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, stringManagerString.str(), args );
va_end(args);

if( result >= 0 )
{
formattedMessage.set( buf );
// add the text to the ui
addMessageText( formattedMessage );
}
else
{
DEBUG_CRASH(("InGameUI::message failed with code:%d", result));
}
} // end

//-------------------------------------------------------------------------------------------------
Expand All @@ -2046,16 +2051,21 @@ void InGameUI::message( UnicodeString format, ... )

// construct the final text after formatting
va_list args;
va_start( args, format );
va_start( args, format );
WideChar buf[ UnicodeString::MAX_FORMAT_BUF_LEN ];
if( _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, format.str(), args ) < 0 )
throw ERROR_OUT_OF_MEMORY;
formattedMessage.set( buf );
va_end(args);

// add the text to the ui
addMessageText( formattedMessage );
int result = _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, format.str(), args );
va_end(args);

if( result >= 0 )
{
formattedMessage.set( buf );
// add the text to the ui
addMessageText( formattedMessage );
}
else
{
DEBUG_CRASH(("InGameUI::message failed with code:%d", result));
}
} // end message

//-------------------------------------------------------------------------------------------------
Expand All @@ -2068,16 +2078,20 @@ void InGameUI::messageColor( const RGBColor *rgbColor, UnicodeString format, ...

// construct the final text after formatting
va_list args;
va_start( args, format );
va_start( args, format );
WideChar buf[ UnicodeString::MAX_FORMAT_BUF_LEN ];
if( _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, format.str(), args ) < 0 )
throw ERROR_OUT_OF_MEMORY;
formattedMessage.set( buf );
va_end(args);

// add the text to the ui
addMessageText( formattedMessage, rgbColor );
int result = _vsnwprintf(buf, sizeof( buf )/sizeof( WideChar ) - 1, format.str(), args );

if( result >= 0 )
{
formattedMessage.set( buf );
// add the text to the ui
addMessageText( formattedMessage, rgbColor );
}
else
{
DEBUG_CRASH(("InGameUI::messageColor failed with code:%d", result));
}
} // end message

//-------------------------------------------------------------------------------------------------
Expand Down
Loading