Skip to content

Commit

Permalink
Merge pull request #5483 from Baezon/hud-gauge-load-safety
Browse files Browse the repository at this point in the history
Improved hud gauge loading safety
  • Loading branch information
TRBlount authored Jul 16, 2023
2 parents 06e74fa + d6ee515 commit 1431270
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 37 deletions.
2 changes: 1 addition & 1 deletion code/bmpman/bmpman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2602,7 +2602,7 @@ void *bm_malloc(int n, size_t size) {
void bm_page_in_aabitmap(int handle, int nframes) {
int i;

if (handle == -1)
if (handle < 0)
return;

Assert(bm_get_entry(handle)->handle == handle);
Expand Down
3 changes: 3 additions & 0 deletions code/hud/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,6 +2961,9 @@ void HudGaugeSupport::render(float /*frametime*/)
int show_time, w, h;
char outstr[64];

if (background.first_frame < 0)
return;

if ( !Hud_support_view_active ) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions code/hud/hudescort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ void HudGaugeEscort::render(float /*frametime*/)
{
int i = 0;

if (Escort_gauges[0].first_frame < 0)
return;

if ( !Show_escort_view ) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions code/hud/hudets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ void HudGaugeEts::pageIn()
*/
void HudGaugeEts::blitGauge(int index)
{
if (Ets_bar.first_frame < 0) {
return;
}

int y_start, y_end, clip_h, w, h, x, y;

clip_h = fl2i( (1 - Energy_levels[index]) * ETS_bar_h );
Expand Down
4 changes: 2 additions & 2 deletions code/hud/hudlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ void HudGaugeLock::renderLockTrianglesOld(int center_x, int center_y, int radius
// draw a frame of the rotating lock triangles animation
void HudGaugeLock::renderLockTriangles(int center_x, int center_y, float frametime)
{
if ( Lock_anim.first_frame == -1 ) {
if ( Lock_anim.first_frame < 0 ) {
renderLockTrianglesOld(center_x, center_y, Lock_target_box_width/2);
} else {
// render the anim
Expand Down Expand Up @@ -1734,7 +1734,7 @@ void HudGaugeLock::renderLockTriangles(int center_x, int center_y, float frameti

void HudGaugeLock::renderLockTrianglesNew(int center_x, int center_y, float frametime, lock_info *slot)
{
if ( Lock_anim.first_frame == -1 ) {
if ( Lock_anim.first_frame < 0 ) {
renderLockTrianglesOld(center_x, center_y, Lock_target_box_width/2);
} else {
// render the anim
Expand Down
20 changes: 18 additions & 2 deletions code/hud/hudreticle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ void HudGaugeReticle::initFirepointDisplay(bool firepoint, int scaleX, int scale

void HudGaugeReticle::render(float /*frametime*/)
{
ship_info *sip = &Ship_info[Player_ship->ship_info_index];
if (crosshair.first_frame < 0) {
return;
}

ship_info *sip = &Ship_info[Player_ship->ship_info_index];

if (autoaim_frame_offset > 0 || sip->autoaim_lock_snd.isValid() || sip->autoaim_lost_snd.isValid()) {
ship *shipp = &Ships[Objects[Player->objnum].instance];
Expand Down Expand Up @@ -533,6 +537,10 @@ void HudGaugeThrottle::pageIn()

void HudGaugeThrottle::render(float /*frametime*/)
{
if (throttle_frames.first_frame < 0) {
return;
}

float desired_speed, max_speed, current_speed, absolute_speed, absolute_displayed_speed, max_displayed_speed, percent_max, percent_aburn_max;
int desired_y_pos, y_end;

Expand Down Expand Up @@ -812,14 +820,19 @@ void HudGaugeThreatIndicator::pageIn()
void HudGaugeThreatIndicator::render(float /*frametime*/)
{
setGaugeColor();
renderBitmap(threat_arc.first_frame+1, position[0], position[1]);

if (threat_arc.first_frame >= 0)
renderBitmap(threat_arc.first_frame+1, position[0], position[1]);

renderLaserThreat();
renderLockThreat();
}

void HudGaugeThreatIndicator::renderLaserThreat()
{
if (laser_warn.first_frame < 0)
return;

int frame_offset, num_frames;

//Check how many frames the ani actually has
Expand All @@ -845,6 +858,9 @@ void HudGaugeThreatIndicator::renderLaserThreat()

void HudGaugeThreatIndicator::renderLockThreat()
{
if (lock_warn.first_frame < 0)
return;

int frame_offset, num_frames;

//Let's find out how many frames our ani has, and adjust accordingly
Expand Down
5 changes: 4 additions & 1 deletion code/hud/hudshield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ void HudGaugeShield::showShields(object *objp, int mode)
if (sip->shield_icon_index != 255) {
sgp = &Shield_gauges.at(sip->shield_icon_index);

if ( (sgp->first_frame == -1) && (sip->shield_icon_index < Hud_shield_filenames.size()) ) {
if ( (sgp->first_frame < 0) && (sip->shield_icon_index < Hud_shield_filenames.size()) ) {
sgp->first_frame = bm_load_animation(Hud_shield_filenames.at(sip->shield_icon_index).c_str(), &sgp->num_frames);
if (sgp->first_frame == -1) {
if (!shield_ani_warning_displayed_already) {
Expand Down Expand Up @@ -958,6 +958,9 @@ void HudGaugeShieldMini::pageIn()
// Draw the miniature shield icon that is drawn near the reticle
void HudGaugeShieldMini::showMiniShields(object *objp)
{
if (Shield_mini_gauge.first_frame < 0)
return;

float max_shield;
int hud_color_index, range, frame_offset;
int sx, sy, i;
Expand Down
46 changes: 28 additions & 18 deletions code/hud/hudtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4826,7 +4826,8 @@ void HudGaugeAutoTarget::render(float /*frametime*/)

// draw the box background
setGaugeColor();
renderBitmap(Toggle_frame.first_frame+frame_offset, position[0], position[1]);
if (Toggle_frame.first_frame + frame_offset >= 0)
renderBitmap(Toggle_frame.first_frame+frame_offset, position[0], position[1]);

// draw the text on top
if (frame_offset == 1) {
Expand Down Expand Up @@ -4912,7 +4913,8 @@ void HudGaugeAutoSpeed::render(float /*frametime*/)

setGaugeColor();

renderBitmap(Toggle_frame.first_frame+frame_offset, position[0], position[1]);
if (Toggle_frame.first_frame + frame_offset >= 0)
renderBitmap(Toggle_frame.first_frame+frame_offset, position[0], position[1]);

// draw the text on top
if (frame_offset == 3) {
Expand Down Expand Up @@ -5501,9 +5503,8 @@ void HudGaugeCmeasures::pageIn()

void HudGaugeCmeasures::render(float /*frametime*/)
{
if ( Cmeasure_gauge.first_frame == -1) {
Int3(); // failed to load coutermeasure gauge background
return;
if ( Cmeasure_gauge.first_frame < 0) {
return; // failed to load coutermeasure gauge background
}

ship_info *sip = &Ship_info[Player_ship->ship_info_index];
Expand Down Expand Up @@ -5551,7 +5552,7 @@ void HudGaugeAfterburner::render(float /*frametime*/)
float percent_left;
int clip_h,w,h;

if ( Energy_bar.first_frame == -1 ){
if ( Energy_bar.first_frame < 0 ){
return;
}

Expand Down Expand Up @@ -5760,7 +5761,7 @@ void HudGaugeWeaponEnergy::render(float /*frametime*/)
weapon_info *wip;
ship_weapon *sw;

if ( Energy_bar.first_frame == -1 ) {
if ( Energy_bar.first_frame < 0 ) {
return;
}

Expand Down Expand Up @@ -6125,7 +6126,8 @@ void HudGaugeWeapons::render(float /*frametime*/)
setGaugeColor();

// draw top of primary display
renderBitmap(primary_top[ballistic_hud_index].first_frame, position[0] + top_offset_x[ballistic_hud_index], position[1]);
if (primary_top[ballistic_hud_index].first_frame >= 0)
renderBitmap(primary_top[ballistic_hud_index].first_frame, position[0] + top_offset_x[ballistic_hud_index], position[1]);

// render the header of this gauge
renderString(position[0] + Weapon_header_offsets[ballistic_hud_index][0], position[1] + Weapon_header_offsets[ballistic_hud_index][1], EG_WEAPON_TITLE, XSTR( "weapons", 328));
Expand All @@ -6145,10 +6147,11 @@ void HudGaugeWeapons::render(float /*frametime*/)
// It is assumed that the top primary wep frame already has this rendered.
if(i == 1) {
// used to draw the second primary weapon background
renderBitmap(primary_middle[ballistic_hud_index].first_frame, position[0] + frame_offset_x[ballistic_hud_index], y);
if (primary_middle[ballistic_hud_index].first_frame >= 0)
renderBitmap(primary_middle[ballistic_hud_index].first_frame, position[0] + frame_offset_x[ballistic_hud_index], y);
} else if(i != 0) {
// used to draw the the third, fourth, fifth, etc...
if(primary_last[ballistic_hud_index].first_frame != -1)
if(primary_last[ballistic_hud_index].first_frame >= 0)
renderBitmap(primary_last[ballistic_hud_index].first_frame, position[0] + frame_offset_x[ballistic_hud_index], y);
}

Expand Down Expand Up @@ -6198,7 +6201,8 @@ void HudGaugeWeapons::render(float /*frametime*/)
setGaugeColor(HUD_C_BRIGHT);
}

renderBitmap(secondary_top[ballistic_hud_index].first_frame, position[0] + frame_offset_x[ballistic_hud_index], y);
if (secondary_top[ballistic_hud_index].first_frame >= 0)
renderBitmap(secondary_top[ballistic_hud_index].first_frame, position[0] + frame_offset_x[ballistic_hud_index], y);
name_y = y + sname_start_offset_y;
y += top_secondary_h;

Expand All @@ -6207,7 +6211,7 @@ void HudGaugeWeapons::render(float /*frametime*/)
setGaugeColor();
wip = &Weapon_info[sw->secondary_bank_weapons[i]];

if(i!=0) {
if(i!=0 && secondary_middle[ballistic_hud_index].first_frame >= 0) {
renderBitmap(secondary_middle[ballistic_hud_index].first_frame, position[0] + frame_offset_x[ballistic_hud_index], y);
}

Expand Down Expand Up @@ -6281,7 +6285,8 @@ void HudGaugeWeapons::render(float /*frametime*/)

y -= 0;
// finish drawing the background
renderBitmap(secondary_bottom[ballistic_hud_index].first_frame, position[0] + frame_offset_x[ballistic_hud_index], y);
if (secondary_bottom[ballistic_hud_index].first_frame >= 0)
renderBitmap(secondary_bottom[ballistic_hud_index].first_frame, position[0] + frame_offset_x[ballistic_hud_index], y);
}

void hud_update_weapon_flash()
Expand Down Expand Up @@ -6843,7 +6848,8 @@ void HudGaugeWarheadCount::render(float /*frametime*/)
column = i;
}

renderBitmap(Warhead.first_frame, position[0] + Warhead_count_offsets[0] + column * delta_x, position[1] + Warhead_count_offsets[1] + delta_y);
if (Warhead.first_frame >= 0)
renderBitmap(Warhead.first_frame, position[0] + Warhead_count_offsets[0] + column * delta_x, position[1] + Warhead_count_offsets[1] + delta_y);
}
}

Expand Down Expand Up @@ -7012,7 +7018,8 @@ void HudGaugePrimaryWeapons::render(float /*frametime*/)

setGaugeColor();

renderBitmap(_background_first.first_frame, position[0], position[1]);
if (_background_first.first_frame >= 0)
renderBitmap(_background_first.first_frame, position[0], position[1]);

// render the header of this gauge
renderString(position[0] + _header_offsets[0], position[1] + _header_offsets[1], EG_WEAPON_TITLE, header_text);
Expand All @@ -7025,7 +7032,8 @@ void HudGaugePrimaryWeapons::render(float /*frametime*/)
for ( i = 0; i < num_primaries; ++i ) {
setGaugeColor();

renderBitmap(_background_entry.first_frame, position[0], position[1] + bg_y_offset);
if (_background_entry.first_frame >= 0)
renderBitmap(_background_entry.first_frame, position[0], position[1] + bg_y_offset);

auto weapon_name = Weapon_info[sw->primary_bank_weapons[i]].get_display_name();

Expand Down Expand Up @@ -7063,13 +7071,15 @@ void HudGaugePrimaryWeapons::render(float /*frametime*/)
}

if ( num_primaries == 0 ) {
renderBitmap(_background_entry.first_frame, position[0], position[1] + bg_y_offset);
if (_background_entry.first_frame >= 0)
renderBitmap(_background_entry.first_frame, position[0], position[1] + bg_y_offset);
renderString(position[0] + _pname_offset_x, position[1] + text_y_offset, EG_WEAPON_P1, XSTR( "<none>", 329));

bg_y_offset += _background_entry_h;
}

renderBitmap(_background_last.first_frame, position[0], position[1] + bg_y_offset + _bg_last_offset_y);
if (_background_last.first_frame >= 0)
renderBitmap(_background_last.first_frame, position[0], position[1] + bg_y_offset + _bg_last_offset_y);
}

HudGaugeSecondaryWeapons::HudGaugeSecondaryWeapons():
Expand Down
12 changes: 7 additions & 5 deletions code/hud/hudtargetbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ void HudGaugeTargetBox::render(float frametime)
setGaugeColor();

// blit the background frame
renderBitmap(Monitor_frame.first_frame, position[0], position[1]);
if (Monitor_frame.first_frame >= 0)
renderBitmap(Monitor_frame.first_frame, position[0], position[1]);

if ( Monitor_mask >= 0 ) {
// render the alpha mask
Expand Down Expand Up @@ -461,8 +462,9 @@ void HudGaugeTargetBox::render(float frametime)
void HudGaugeTargetBox::renderTargetForeground()
{
setGaugeColor();

renderBitmap(Monitor_frame.first_frame+1, position[0], position[1]);

if (Monitor_frame.first_frame + 1 >= 0)
renderBitmap(Monitor_frame.first_frame+1, position[0], position[1]);
}

/**
Expand All @@ -473,7 +475,7 @@ void HudGaugeTargetBox::renderTargetIntegrity(int disabled,int force_obj_num)
int clip_h,w,h;
char buf[16];

if ( Integrity_bar.first_frame == -1 )
if ( Integrity_bar.first_frame < 0 )
return;

if ( disabled ) {
Expand Down Expand Up @@ -1580,7 +1582,7 @@ void HudGaugeExtraTargetData::render(float /*frametime*/)
extra_data_shown=1;
}

if ( extra_data_shown ) {
if ( extra_data_shown && bracket.first_frame >= 0) {
renderBitmap(bracket.first_frame, position[0] + bracket_offsets[0], position[1] + bracket_offsets[1]);
}
}
Expand Down
5 changes: 3 additions & 2 deletions code/hud/hudwingmanstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void HudGaugeWingmanStatus::renderBackground(int num_wings_to_draw)

sy += right_frame_start_offset;
} else {
if(num_wings_to_draw > 2 && bitmap > 0) {
if(num_wings_to_draw > 2 && bitmap >= 0) {
for(int i = 0; i < num_wings_to_draw - 2; i++){
renderBitmap(bitmap, sx, sy);
sx += wing_width;
Expand All @@ -399,7 +399,8 @@ void HudGaugeWingmanStatus::renderBackground(int num_wings_to_draw)
}

bitmap = Wingman_status_right.first_frame;
renderBitmap(bitmap, sx, sy);
if (bitmap >= 0)
renderBitmap(bitmap, sx, sy);
}

void HudGaugeWingmanStatus::renderDots(int wing_index, int screen_index, int num_wings_to_draw)
Expand Down
13 changes: 9 additions & 4 deletions code/mission/missiontraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ void HudGaugeDirectives::render(float /*frametime*/)
// draw top of objective display
setGaugeColor();

renderBitmap(directives_top.first_frame, position[0], position[1]);
if (directives_top.first_frame >= 0)
renderBitmap(directives_top.first_frame, position[0], position[1]);

// print out title
renderPrintf(position[0] + header_offsets[0], position[1] + header_offsets[1], EG_OBJ_TITLE, "%s", XSTR( "directives", 422));
Expand Down Expand Up @@ -303,12 +304,15 @@ void HudGaugeDirectives::render(float /*frametime*/)
// blit the background frames
setGaugeColor();

renderBitmap(directives_middle.first_frame, bx, by);
if (directives_middle.first_frame >= 0)
renderBitmap(directives_middle.first_frame, bx, by);

by += text_h;

if ( second_line ) {
renderBitmap(directives_middle.first_frame, bx, by);

if (directives_top.first_frame >= 0)
renderBitmap(directives_middle.first_frame, bx, by);

by += text_h;
}
Expand All @@ -332,7 +336,8 @@ void HudGaugeDirectives::render(float /*frametime*/)
// draw the bottom of objective display
setGaugeColor();

renderBitmap(directives_bottom.first_frame, bx, by + bottom_bg_offset);
if (directives_bottom.first_frame >= 0)
renderBitmap(directives_bottom.first_frame, bx, by + bottom_bg_offset);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion code/radar/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ void HudGaugeRadarStd::blipDrawFlicker(blip *b, int x, int y)
}
void HudGaugeRadarStd::blitGauge()
{
renderBitmap(Radar_gauge.first_frame+1, position[0], position[1] );
if (Radar_gauge.first_frame + 1 >= 0)
renderBitmap(Radar_gauge.first_frame+1, position[0], position[1] );
}
void HudGaugeRadarStd::drawBlips(int blip_type, int bright, int distort)
{
Expand Down
Loading

0 comments on commit 1431270

Please sign in to comment.