Skip to content

Commit 7590eaa

Browse files
authored
Fix dirty modelcollide state in shipfx and harden with assert (#7390)
1 parent d98b117 commit 7590eaa

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

code/model/modelcollide.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,8 @@ int model_collide(mc_info *mc_info_obj)
11501150
Mc_pmi = NULL;
11511151
}
11521152

1153-
if (Mc_pmi && Mc->collision_checked.empty()) {
1153+
if (Mc_pmi && Mc->collision_checked.size() != static_cast<size_t>(Mc_pm->n_models)) {
1154+
Assertion(Mc->collision_checked.empty(), "model_collide was called with a dirty mc_info state! Please report to the SCP.");
11541155
Mc->collision_checked.resize(Mc_pm->n_models, 0);
11551156
}
11561157

code/ship/shipfx.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,7 @@ bool shipfx_eye_in_shadow( vec3d *eye_pos, object * src_obj, int light_n )
791791
vec3d rp0, rp1;
792792
vec3d light_dir;
793793

794-
// The mc_info struct only needs to be initialized once for this entire function. This is because
795-
// every time the mc variable is reused, every parameter that model_collide reads from is reassigned.
796-
// Therefore the stale fields in the rest of the struct do not matter because either a) they are never
797-
// read from, or b) they are overwritten by the new collision calculation.
798-
mc_info mc;
799-
800-
rp0 = *eye_pos;
794+
rp0 = *eye_pos;
801795

802796
// get the light dir
803797
if(!light_get_global_dir(&light_dir, light_n)){
@@ -811,6 +805,8 @@ bool shipfx_eye_in_shadow( vec3d *eye_pos, object * src_obj, int light_n )
811805
continue;
812806

813807
if ( src_obj != objp ) {
808+
mc_info mc;
809+
814810
vm_vec_scale_add( &rp1, &rp0, &light_dir, objp->radius*10.0f );
815811

816812
mc.model_instance_num = Ships[objp->instance].model_instance_num;
@@ -834,6 +830,8 @@ bool shipfx_eye_in_shadow( vec3d *eye_pos, object * src_obj, int light_n )
834830
continue;
835831

836832
if (src_obj != objp) {
833+
mc_info mc;
834+
837835
vm_vec_scale_add(&rp1, &rp0, &light_dir, objp->radius * 10.0f);
838836

839837
mc.model_instance_num = p->model_instance_num;
@@ -861,6 +859,8 @@ bool shipfx_eye_in_shadow( vec3d *eye_pos, object * src_obj, int light_n )
861859

862860
vm_vec_scale_add( &rp1, &rp0, &light_dir, objp->radius*10.0f );
863861

862+
mc_info mc;
863+
864864
mc.model_instance_num = -1;
865865
mc.model_num = db.model_num; // Fill in the model to check
866866
mc.submodel_num = db.submodel_num;
@@ -889,6 +889,8 @@ bool shipfx_eye_in_shadow( vec3d *eye_pos, object * src_obj, int light_n )
889889
vm_vec_unrotate(&pos, &sip->cockpit_offset, &eye_ori);
890890
vm_vec_add2(&pos, &eye_posi);
891891

892+
mc_info mc;
893+
892894
mc.model_instance_num = -1;
893895
mc.model_num = sip->cockpit_model_num;
894896
mc.submodel_num = -1;
@@ -938,6 +940,8 @@ bool shipfx_eye_in_shadow( vec3d *eye_pos, object * src_obj, int light_n )
938940
&& (!Show_ship_only_if_cockpits_enabled || Cockpit_active) ) {
939941
vm_vec_scale_add( &rp1, &rp0, &light_dir, Viewer_obj->radius*10.0f );
940942

943+
mc_info mc;
944+
941945
mc.model_instance_num = -1;
942946
mc.model_num = sip->model_num;
943947
mc.submodel_num = -1;
@@ -1001,6 +1005,8 @@ bool shipfx_eye_in_shadow( vec3d *eye_pos, object * src_obj, int light_n )
10011005

10021006
vm_vec_scale_add( &rp1, &rp0, &light_dir, objp->radius*10.0f );
10031007

1008+
mc_info mc;
1009+
10041010
mc.model_instance_num = -1;
10051011
mc.model_num = Asteroid_info[ast->asteroid_type].subtypes[ast->asteroid_subtype].model_number; // Fill in the model to check
10061012
mc.submodel_num = -1;

0 commit comments

Comments
 (0)