Some drills not removing voxels

Иван Космак shared this bug 3 years ago
Reported

Sandbox.Game.GameSystems.MyShipMiningSystem.ScheduleCutouts() : void @0600448F


The "for" loop works correctly only on the first iteration. The first drill is lost on the following cycles.

You need to add "i--" to count the missed drill on the next cycle.

int length = i - num;
i--;

Replies (2)

photo
1

How to create bad drill at small/large grid.. It's simple:


fcfb386fd94ffc4db445656e02662b7f

For example add 4 drills: Drill 1 and drill 2 in cluster 1. Drill 3 and drill 4 in cluster 2.

What happens in the code step by step:

// we will be drilling one object, so all of Voxel is same
// we have 4 drills, so m_pCO.Count is 4,
// m_pCO[0] is info of drill 1, m_pCO[1] is info of drill 2,
// m_pCO[2] is info of drill 3, m_pCO[3] is info of drill 4
for (int i = 0; i < m_pCO.Count; i++)
	// i = 0 ; 0 < 4 is true, go in
{
	MySMS.COR COR = m_pCO[i];
	// COR = m_pCO[0]
	var vT = new vT<MySMS.DC, MyVB>(COR.Cluster, COR.Voxel);
	// remembering cluster and voxel of drill 1
	int num = i;
	// num = 0
	while (i < m_pCO.Count)
		// 0 < 4 is true, go in
	{
		MySMS.COR COR2 = m_pCO[i];
		// COR2 = m_pCO[0]
		if (COR2.Cluster != vT.Item1 || COR2.Voxel != vT.Item2)
			// COR and COR2 is same drill so false or false is false
		i++;
		// i = 1
		
		(i < m_pCO.Count)
		// 1 < 4 is true, continue
		MySMS.COR COR2 = m_pCO[i];
		// COR2 = m_pCO[1]
		if (COR2.Cluster != vT.Item1 || COR2.Voxel != vT.Item2)
			// drill 2 and drill 1 in cluster 1 so false or false is false
		i++;		
		// i = 2
		
		(i < m_pCO.Count)
		// 2 < 4 is true, continue
		MySMS.COR COR2 = m_pCO[i];
		// COR2 = m_pCO[2]
		if (COR2.Cluster != vT.Item1 || COR2.Voxel != vT.Item2)
			// drill 3 in cluster 2 and drill 1 in cluster 1 so true or false is true
		{
			break;
			// go out of the "while" cycle
		}
	}
	int length = i - num;
	// length = 2 - 0
	MySMS.CCO.GAP(..., m_pCO.Slice(num, length))...;
	// add to remove voxels begin m_pCO[0] and length = 2 (drill 1 and drill 2)
	
	(int i = 0; i < m_pCO.Count; i++)
	// i = 3 ; 3 < 4 is true, continue
	MySMS.COR COR = m_pCO[i];
	// COR = m_pCO[3]
	var vT = new vT<MySMS.DC, MyVB>(COR.Cluster, COR.Voxel);
	// remembering cluster and voxel of drill 4
	int num = i;
	// num = 3
	while (i < m_pCO.Count)
		// 3 < 4 is true, go in
	{
		MySMS.COR COR2 = m_pCO[i];
		// COR2 = m_pCO[3]
		if (COR2.Cluster != vT.Item1 || COR2.Voxel != vT.Item2)
			// COR and COR2 is same drill so false or false is false
		i++;
		// i = 4
		
		(i < m_pCO.Count)
		// 4 < 4 is false, go out of the "while" cycle
	}
	int length = i - num;
	// length = 4 - 3
	MySMS.CCO.GAP(..., m_pCO.Slice(num, length))...;
	// add to remove voxels begin m_pCO[3] and length = 1 (drill 4)
	(int i = 0; i < m_pCO.Count; i++)
	// i = 5 ; 5 < 4 is false, go out of the "for" cycle
}

As you see drill 3 was throw out of lists of remove voxels.


After trow out "i++" from the iterator section of the "for" cycle and add "i++" before "while" cycle we will fix bug and do not compare drill with itself.

// we will be drilling one object, so all of Voxel is same
// we have 4 drills, so m_pCO.Count is 4,
// m_pCO[0] is info of drill 1, m_pCO[1] is info of drill 2,
// m_pCO[2] is info of drill 3, m_pCO[3] is info of drill 4
for (int i = 0; i < m_pCO.Count; )
	// i = 0 ; 0 < 4 is true, go in
{
	MySMS.COR COR = m_pCO[i];
	// COR = m_pCO[0]
	var vT = new vT<MySMS.DC, MyVB>(COR.Cluster, COR.Voxel);
	// remembering cluster and voxel of drill 1
	int num = i;
	// num = 0
	i++;
	// i = 1
	while (i < m_pCO.Count)
		// 1 < 4 is true, go in
	{
		MySMS.COR COR2 = m_pCO[i];
		// COR2 = m_pCO[1]
		if (COR2.Cluster != vT.Item1 || COR2.Voxel != vT.Item2)
			// drill 2 and drill 1 in cluster 1 so false or false is false
		i++;
		// i = 2
		
		(i < m_pCO.Count)
		// 2 < 4 is true, continue
		MySMS.COR COR2 = m_pCO[i];
		// COR2 = m_pCO[2]
		if (COR2.Cluster != vT.Item1 || COR2.Voxel != vT.Item2)
			// drill 3 in cluster 2 and drill 1 in cluster 1 so true or false is true
		{
			break;
			// go out of the "while" cycle
		}
	}
	int length = i - num;
	// length = 2 - 0
	MySMS.CCO.GAP(..., m_pCO.Slice(num, length))...;
	// add to remove voxels begin m_pCO[0] and length = 2 (drill 1 and drill 2)
	
	(int i = 0; i < m_pCO.Count; )
	// 2 < 4 is true, continue
	MySMS.COR COR = m_pCO[i];
	// COR = m_pCO[2]
	var vT = new vT<MySMS.DC, MyVB>(COR.Cluster, COR.Voxel);
	// remembering cluster and voxel of drill 3
	int num = i;
	// num = 2
	i++;
	// i = 3
	while (i < m_pCO.Count)
		// 3 < 4 is true, go in
	{
		MySMS.COR COR2 = m_pCO[i];
		// COR2 = m_pCO[3]
		if (COR2.Cluster != vT.Item1 || COR2.Voxel != vT.Item2)
			// drill 4 and drill 3 in cluster 2 so false or false is false
		i++;
		// i = 4
		
		(i < m_pCO.Count)
		// 4 < 4 is false, go out of the "while" cycle
	}
	int length = i - num;
	// length = 4 - 2
	MySMS.CCO.GAP(..., m_pCO.Slice(num, length))...;
	// add to remove voxels begin m_pCO[2] and length = 2 (drill 3 and drill 4)
	(int i = 0; i < m_pCO.Count; )
	// 4 < 4 is false, go out of the "for" cycle
}

Now all 4 drills has added to lists of remove voxels.


photo
1

Hello!

Thank you for letting us know about this issue. This has been reported internally

Kind Regards

Laura, QA Department

Leave a Comment
 
Attach a file