Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 2f666f9

Browse files
committed
Fixed a threading error in GridGroups. Fixes #90
1 parent 6fd4a25 commit 2f666f9

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//83
1+
//96
22
//
33
// This code was generated by a tool. Any changes made manually will be lost
44
// the next time this code is regenerated.
55
//
66

77
using System.Reflection;
88

9-
[assembly: AssemblyFileVersion("1.13.6.83")]
10-
[assembly: AssemblyVersion("1.13.6.83")]
9+
[assembly: AssemblyFileVersion("1.13.6.96")]
10+
[assembly: AssemblyVersion("1.13.6.96")]

EssentialsPlugin/ChatHandlers/AdminScan/HandleAdminScanNoBeacon.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ public override bool HandleCommand(ulong userId, string[] words)
6262

6363
try
6464
{
65-
string command = $"excludesblocksubtype:beacon{linkType} quiet";
65+
string command = $"excludesblocksubtype:beacon quiet{linkType}";
6666
HashSet<GridGroup> groups = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray());
67-
int groupsCount = 0;
67+
int groupsCount = groups.Count;
6868
int gridsCount = 0;
6969

7070
foreach ( var group in groups )
7171
{
72-
if ( group.GetFatBlocks( ).Any( x => x is IMyBeacon ) )
73-
continue;
72+
//if ( group.GetFatBlocks( ).Any( x => x is IMyBeacon ) )
73+
// continue;
7474

75-
groupsCount++;
75+
//groupsCount++;
7676
gridsCount += group.Grids.Count;
7777
Communication.SendPrivateInformation( userId, $"Found group with parent {group.Parent.DisplayName} ({group.Parent.EntityId}) at {group.Parent.PositionComp.GetPosition( )} with no beacon." );
7878
}

EssentialsPlugin/Utility/CubeGrid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
867867
//if (!quiet)
868868
Communication.SendPrivateInformation( userId, $"Found {gridCount} grids in {groupCount} groups" );
869869

870-
return groupsToConfirm;
870+
return groupsFound;
871871
}
872872

873873
public static bool IsFullOwner( MyCubeGrid grid, long ownerId, IMyPlayer factionPlayer = null )

EssentialsPlugin/Utility/GridGroup.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Sandbox.Game.Entities;
1010
using Sandbox.Game.Entities.Cube;
1111
using VRage.Game.Entity;
12+
using VRage.ModAPI;
1213
using VRageMath;
1314

1415
public class GridGroup
@@ -69,20 +70,28 @@ public MyCubeGrid Parent
6970

7071
public GridGroup( MyCubeGrid grid, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical )
7172
{
72-
//HACK: Manually create a group for out of scene grids because pulling them from the server crashes
7373
if ( grid.InScene )
7474
{
7575
List<MyCubeGrid> tmpList = new List<MyCubeGrid>( );
7676

7777
//find the group containing this grid with the given link type
7878
Wrapper.GameAction( ( ) => tmpList = MyCubeGridGroups.Static.GetGroups( linkType ).GetGroupNodes( grid ) );
79-
80-
foreach ( MyCubeGrid node in tmpList )
81-
_grids.Add( node );
79+
80+
_grids.UnionWith( tmpList );
8281
}
82+
//HACK: Manually create a group for out of scene grids because pulling them from the server crashes
8383
else
8484
{
85-
_grids.Add( grid );
85+
//use the old method to filter out grids with pisons or rotors, for safety
86+
HashSet<IMyEntity> thisEntity = new HashSet<IMyEntity>();
87+
HashSet<IMyEntity> returnSet = new HashSet<IMyEntity>();
88+
thisEntity.Add( grid );
89+
CubeGrids.GetGridsUnconnected( thisEntity, returnSet );
90+
91+
if ( returnSet.Count != 0 )
92+
_grids.Add( (MyCubeGrid)returnSet.First( ) );
93+
else
94+
return;
8695
}
8796

8897
//populate our internal lists
@@ -114,12 +123,12 @@ public static HashSet<GridGroup> GetGroups( HashSet<MyEntity> entities, GridLink
114123
//on large servers this can run into the tens of seconds, so parallelize it
115124
groupTasks.Add( Task.Run( ( ) =>
116125
{
117-
if ( result.Any( x => x.Grids.Contains( grid ) ) )
118-
return;
126+
var newGroup = new GridGroup( grid, linkType );
119127

120128
lock ( result )
121129
{
122-
result.Add( new GridGroup( grid, linkType ) );
130+
if ( !result.Any( x => x.Grids.Contains( grid ) ) )
131+
result.Add( newGroup );
123132
}
124133
} ) );
125134
}

0 commit comments

Comments
 (0)