View Issue Details

IDProjectCategoryView StatusLast Update
0002707FSSCPturretspublic2012-12-15 21:16
Reporterheaddie Assigned ToValathil  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
PlatformPCOSWindowsOS VersionXP SP2
Product Version3.6.14 RC6 
Summary0002707: crash using $Substitute: and Turrets
DescriptionWhen using a weapon that uses the substitute table option on a ship turret the game runs fine until a turret using the weapon is fired where the game crashes to desktop with
 
ASSERTION: "position != NULL" at weapons.cpp:4835
 'Ship Name' is trying to fire a weapon that is not selected
Freeing all existing models...

while asking about it on HLP zookeeper identified the problem to be a bug in the game engine.
Steps To Reproduceadd
 
$Substitute: Maxim
    +period: 6

to a blob turret and run a mission where a turret fires the weapon.
Additional Informationissue identified in 3.6.14 RC8 not RC6 as identified above as there is no RC8 option

Substitute weapons seem to work fine on fighters

original post http://www.hard-light.net/forums/index.php?topic=81865.msg1634018#msg1634018

link to $Substitute: in the wiki http://www.hard-light.net/forums/index.php?topic=81865.msg1634018#msg1634018
TagsNo tags attached.

Activities

MjnMixael

2012-12-15 19:01

manager  

2707-wep.tbm (1,531 bytes)

MjnMixael

2012-12-15 19:02

manager  

2707.fs2 (5,874 bytes)

MjnMixael

2012-12-15 19:02

manager   ~0014469

Confirmed. Use the tbm and mission provided to reproduce.

Valathil

2012-12-15 20:52

developer  

2707.patch (4,970 bytes)   
Index: code/ai/aiturret.cpp
===================================================================
--- code/ai/aiturret.cpp	(revision 9437)
+++ code/ai/aiturret.cpp	(working copy)
@@ -1808,7 +1808,7 @@
 				// so we need to get the position info separately for each shot
 				ship_get_global_turret_gun_info(&Objects[parent_objnum], turret, turret_pos, turret_fvec, 1, NULL);
 
-				weapon_objnum = weapon_create( turret_pos, &turret_orient, turret_weapon_class, parent_objnum, -1, 1);
+				weapon_objnum = weapon_create( turret_pos, &turret_orient, turret_weapon_class, parent_objnum, -1, 1, 0,0.0f, turret);
 				weapon_set_tracking_info(weapon_objnum, parent_objnum, turret->turret_enemy_objnum, 1, turret->targeted_subsys);		
 			
 
@@ -1927,7 +1927,7 @@
 	vm_vector_2_matrix(&turret_orient, &turret_fvec, NULL, NULL);
 
 	// create weapon and homing info
-	weapon_objnum = weapon_create(&turret_pos, &turret_orient, tsi->weapon_class, tsi->parent_objnum, -1, 1);
+	weapon_objnum = weapon_create(&turret_pos, &turret_orient, tsi->weapon_class, tsi->parent_objnum, -1, 1, 0, 0.0f, tsi->turret);
 	weapon_set_tracking_info(weapon_objnum, tsi->parent_objnum, tsi->target_objnum, 1, tsi->target_subsys);
 
 	// do other cool stuff if weapon is created.
Index: code/network/multimsgs.cpp
===================================================================
--- code/network/multimsgs.cpp	(revision 9437)
+++ code/network/multimsgs.cpp	(working copy)
@@ -3327,7 +3327,7 @@
 		multi_set_network_signature( wnet_signature, MULTI_SIG_NON_PERMANENT );
 	}
 
-	weapon_objnum = weapon_create( &pos, &orient, wid, OBJ_INDEX(objp), -1, 1);
+	weapon_objnum = weapon_create( &pos, &orient, wid, OBJ_INDEX(objp), -1, 1, 0, 0.0f, ssp);
 	if (weapon_objnum != -1) {
 		if ( Weapon_info[wid].launch_snd != -1 ) {
 			snd_play_3d( &Snds[Weapon_info[wid].launch_snd], &pos, &View_position );
@@ -8383,7 +8383,7 @@
 	ship_get_global_turret_info(objp, ssp->system_info, &pos, &dir);
 
 	// create the weapon object	
-	weapon_objnum = weapon_create( &pos, &orient, wid, OBJ_INDEX(objp), -1, 1);
+	weapon_objnum = weapon_create( &pos, &orient, wid, OBJ_INDEX(objp), -1, 1, 0, 0.0f, ssp);
 	if (weapon_objnum != -1) {
 		if ( Weapon_info[wid].launch_snd != -1 ) {
 			snd_play_3d( &Snds[Weapon_info[wid].launch_snd], &pos, &View_position );
Index: code/weapon/weapon.h
===================================================================
--- code/weapon/weapon.h	(revision 9437)
+++ code/weapon/weapon.h	(working copy)
@@ -611,7 +611,7 @@
 
 // Passing a group_id of -1 means it isn't in a group.  See weapon_create_group_id for more 
 // help on weapon groups.
-int weapon_create( vec3d * pos, matrix * orient, int weapon_type, int parent_obj, int group_id=-1, int is_locked = 0, int is_spawned = 0, float fof_cooldown = 0.0f);
+int weapon_create( vec3d * pos, matrix * orient, int weapon_type, int parent_obj, int group_id=-1, int is_locked = 0, int is_spawned = 0, float fof_cooldown = 0.0f, ship_subsys * src_turret = NULL);
 void weapon_set_tracking_info(int weapon_objnum, int parent_objnum, int target_objnum, int target_is_locked = 0, ship_subsys *target_subsys = NULL);
 
 // for weapons flagged as particle spewers, spew particles. wheee
Index: code/weapon/weapons.cpp
===================================================================
--- code/weapon/weapons.cpp	(revision 9437)
+++ code/weapon/weapons.cpp	(working copy)
@@ -4870,9 +4870,13 @@
 	}
 }
 
-inline size_t* get_pointer_to_weapon_fire_pattern_index(int weapon_type, ship* shipp) {
+inline size_t* get_pointer_to_weapon_fire_pattern_index(int weapon_type, ship* shipp, ship_subsys * src_turret) {
 	Assert( shipp != NULL );
 	ship_weapon* ship_weapon_p = &(shipp->weapons);
+	if(src_turret)
+	{
+		ship_weapon_p = &src_turret->weapons;
+	}
 	Assert( ship_weapon_p != NULL );
 
 	// search for the corresponding bank pattern index for the weapon_type that is being fired.
@@ -4897,7 +4901,7 @@
  * @return Index of weapon in the Objects[] array, -1 if the weapon object was not created
  */
 int Weapons_created = 0;
-int weapon_create( vec3d * pos, matrix * porient, int weapon_type, int parent_objnum, int group_id, int is_locked, int is_spawned, float fof_cooldown)
+int weapon_create( vec3d * pos, matrix * porient, int weapon_type, int parent_objnum, int group_id, int is_locked, int is_spawned, float fof_cooldown, ship_subsys * src_turret)
 {
 	int			n, objnum;
 	int num_deleted;
@@ -4931,7 +4935,7 @@
 		ship* parent_shipp = &(Ships[parent_objp->instance]);
 		Assert( parent_shipp != NULL );
 
-		size_t *position = get_pointer_to_weapon_fire_pattern_index(weapon_type, parent_shipp);
+		size_t *position = get_pointer_to_weapon_fire_pattern_index(weapon_type, parent_shipp, src_turret);
 		Assertion( position != NULL, "'%s' is trying to fire a weapon that is not selected", Ships[parent_objp->instance].ship_name );
 
 		*position = ++(*position) % wip->weapon_substitution_pattern.size();
2707.patch (4,970 bytes)   

Valathil

2012-12-15 20:53

developer   ~0014478

Attached a patch that fixes. Please review

iss_mneur

2012-12-15 21:09

developer   ~0014479

Yes. Valthils solution looks fine. Exactly, what I was going to do when I found the time to fix it and test it.

Valathil

2012-12-15 21:16

developer   ~0014480

Fix committed to trunk@9439.

Related Changesets

fs2open: trunk r9439

2012-12-15 16:47

Valathil


Ported: N/A

Details Diff
Fix for Mantis 2707: Pass the firing turret to weapon_create so it knows where to look for when using $Substitute. Affected Issues
0002707
mod - /trunk/fs2_open/code/ai/aiturret.cpp Diff File
mod - /trunk/fs2_open/code/network/multimsgs.cpp Diff File
mod - /trunk/fs2_open/code/weapon/weapon.h Diff File
mod - /trunk/fs2_open/code/weapon/weapons.cpp Diff File

Issue History

Date Modified Username Field Change
2012-09-04 10:53 headdie New Issue
2012-12-15 19:01 MjnMixael File Added: 2707-wep.tbm
2012-12-15 19:02 MjnMixael File Added: 2707.fs2
2012-12-15 19:02 MjnMixael Note Added: 0014469
2012-12-15 20:52 Valathil File Added: 2707.patch
2012-12-15 20:52 Valathil Assigned To => Valathil
2012-12-15 20:52 Valathil Status new => assigned
2012-12-15 20:53 Valathil Note Added: 0014478
2012-12-15 20:53 Valathil Status assigned => code review
2012-12-15 21:09 iss_mneur Note Added: 0014479
2012-12-15 21:16 Valathil Changeset attached => fs2open trunk r9439
2012-12-15 21:16 Valathil Note Added: 0014480
2012-12-15 21:16 Valathil Status code review => resolved
2012-12-15 21:16 Valathil Resolution open => fixed