-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ecs] Potential Duplicate Entity Problem? #448
Comments
Actually, after we were done testing we both went off and I came back on later and saw the server had restarted/crashed. I went into the log and saw an exception before the crash when my buddy was writing something to me right after I left the server. There were no exceptions when we were both online.
|
All sampsharp does is splitting messages longer than limit to separate messages. Haven't seen this happen before. Based on your code it may indicate |
Apart from the earlier exception I also found this:
What's strange about this one is that I'm not even using Player in the ChickenCoopManager and it's certainly not used in any OnPlayerDisconnect. public ChickenCoopManager(IEntityManager entityManager, IStreamerService streamerService)
{
_entityManager = entityManager;
_streamerService = streamerService;
_recurringTimer = new Timer(_ => RecurringTimer(), null, TimeSpan.Zero, TimeSpan.FromMinutes(10)); // Line 23
}
private void RecurringTimer()
{
foreach (ChickenCoop.Components.ChickenCoop chickenCoop in GetAllChickenCoops()) // Line 28
{
chickenCoop.UpdateChickenCoop(_entityManager);
}
} EDIT: Player is used in the ChickenCoop component, though: public void UpdateChickenCoop(IEntityManager entityManager)
{
if (DateTime.Now > _nextChickenBred)
{
_chickens++;
_nextChickenBred = DateTime.Now.AddHours(1);
foreach (Player player in entityManager.GetComponents<Player>())
{
player.PlayOpenCdnStream("sfx", "chickenActivity.mp3", _objectLinkedTo.Position, 3.0f);
}
}
if (DateTime.Now > _nextEggLaid)
{
if (_chickens > 0)
{
Random randomEggCount = new Random();
int eggsLaid = randomEggCount.Next(_chickens) + 1;
_eggs += eggsLaid;
_nextEggLaid = DateTime.Now.AddMinutes(15);
if (eggsLaid > 0)
{
foreach (Player player in entityManager.GetComponents<Player>()) // Line 74
{
player.PlayOpenCdnStream("sfx", "chickenEggPop.mp3", _objectLinkedTo.Position, 3.0f);
}
}
}
}
UpdateTextLabel();
} It's not unthinkable an exception could occur in OnPlayerDisconnect, but this is also the only OnPlayerDisconnect in my code that I have at this moment: [Event]
public void OnPlayerDisconnect(Player player, DisconnectReason disconnectReason, IDiscordService discordService)
{
#if (!DEBUG)
if (player.IsPlayerPlayingAsCharacter())
{
discordService.SendGeneralChatMessage($"## {player.Name.Replace("_", " ")} is no longer playing on the server.");
}
#endif
} It's just strange that I don't see any mention of this in the exceptions. At the time of execution, Player should still exist considering the message with Player name does show up in Discord. |
The previously mentioned exception might occur due to not being executed on the main thread. maybe using a system timer could help resolve that. [Timer(60000)]
public void Every60Sec(IServerService serverService)
{
Console.WriteLine($"Every 60 seconds timer! tick rate: {serverService.TickRate}");
} That Maybe you can add some debug logging to an |
Didn't know about the Timer attribute being part of SampSharp, thanks for teaching me something new! 😊 As for the try-catch, wouldn’t it make more sense to have it implemented in SampSharp itself at the point where all the individual system events such as OnPlayerDisconnected are triggered? Or is not doing so an intentional design choice? Either way, I'll add a try-catch around the code in the OnPlayerDisconnect and build in that extra logging to enumerate over entityManager.GetComponents() and check how many entities exist if this issue happens again. It’s the first time I’ve encountered something like this, and restarting the server fixed it immediately. Hopefully, with these changes, I can pinpoint the cause more easily if it recurs. Thanks for the input! |
yes it would indeed, but this will be quicker for now |
@KoertLichtendonk I've added a try/finally in the 0.11.0 update. ae3973f |
I assume that this is a rare SampSharp bug that occurs in some weirdly specific situation as I have no other explanation for this. On my server it randomly started sending double messages in chat to every player. Never had this happen before, and haven't done any changes to the chat logic that could've caused it.
The OOC command loops through every Player and does SendClientMessage, so I don't think there can go much wrong on my side. It almost feels like there are two of the same Player entities.
Unfortunately there isn't much else I can tell you to narrow down the potential issue, it randomly happened after I logged in, before that everything was fine. Here is the /ooc code:
I'm curious if anyone else has ever had this issue?
I have a Discord bot that sends messages from /ooc to Discord, and in Discord only one message appears, which is another reason that leads me to believe this might be a rare SampSharp bug.
The text was updated successfully, but these errors were encountered: