diff --git a/Content.Server/Voting/Managers/VoteManager.cs b/Content.Server/Voting/Managers/VoteManager.cs index 10b975fdcac..71cd5fb2676 100644 --- a/Content.Server/Voting/Managers/VoteManager.cs +++ b/Content.Server/Voting/Managers/VoteManager.cs @@ -393,12 +393,23 @@ private void EndVote(VoteReg v) } // Find winner or stalemate. - var winners = v.Entries - .GroupBy(e => e.Votes) - .OrderByDescending(g => g.Key) - .First() - .Select(e => e.Data) - .ToImmutableArray(); + // Sunrise-Start: На случай пустых голосований + ImmutableArray winners; + if (v.Entries.Any()) + { + winners = v.Entries + .GroupBy(e => e.Votes) + .OrderByDescending(g => g.Key) + .First() + .Select(e => e.Data) + .ToImmutableArray(); + } + else + { + winners = ImmutableArray.Empty; + } + // Sunrise-End + // Store all votes in order for webhooks var voteTally = new List(); foreach(var entry in v.Entries) @@ -408,8 +419,18 @@ private void EndVote(VoteReg v) v.Finished = true; v.Dirty = true; - var args = new VoteFinishedEventArgs(winners.Length == 1 ? winners[0] : null, winners, voteTally); - v.OnFinished?.Invoke(_voteHandles[v.Id], args); + // Sunrise-Start: На случай пустых голосований + if (_voteHandles.ContainsKey(v.Id)) + { + var args = new VoteFinishedEventArgs(winners.Length == 1 ? winners[0] : null, winners, voteTally); + v.OnFinished?.Invoke(_voteHandles[v.Id], args); + } + else + { + Logger.Error($"Vote handle with Id {v.Id} does not exist in _voteHandles."); + } + // Sunrise-End + DirtyCanCallVoteAll(); }