thebigsleepjoe / TTT-Bots-2

Player bots for Garry's Mod TTT
Creative Commons Attribution Share Alike 4.0 International
10 stars 2 forks source link

[BUG] retrying clients causes bots to behave strangely #34

Closed EntranceJew closed 6 months ago

EntranceJew commented 7 months ago

Game version/server type

Describe the bug

Creating bots broken after forced retry.

Stack trace/error

The error, if any. Example:

CreatePlayerBot: Unable to create bot [BOT] Pootis - CreateFakeClient() returned NULL.

[TTT Bots 2.0] lua/tttbots2/components/sv_locomotor.lua:52: attempt to index local 'bot' (a nil value)
  1. Initialize - lua/tttbots2/components/sv_locomotor.lua:52
   2. New - lua/tttbots2/components/sv_locomotor.lua:21
    3. CreateBot - lua/tttbots2/lib/sh_botlib.lua:829
     4. serverCallback - lua/tttbots2/commands/sh_concommands.lua:65
      5. unknown - lua/tttbots2/commands/sh_concommands.lua:50
       6. unknown - lua/includes/modules/concommand.lua:54

CreatePlayerBot: Unable to create bot [BOT] Hugh Mungus - CreateFakeClient() returned NULL.

[TTT Bots 2.0] lua/tttbots2/components/sv_locomotor.lua:52: attempt to index local 'bot' (a nil value)
  1. Initialize - lua/tttbots2/components/sv_locomotor.lua:52
   2. New - lua/tttbots2/components/sv_locomotor.lua:21
    3. CreateBot - lua/tttbots2/lib/sh_botlib.lua:829
     4. serverCallback - lua/tttbots2/commands/sh_concommands.lua:65
      5. unknown - lua/tttbots2/commands/sh_concommands.lua:50
       6. unknown - lua/includes/modules/concommand.lua:54

Reproducing the bug

Steps to reproduce the behavior:

  1. Enter a round with bots.
  2. Force all clients to retry in console.
  3. Bots will be punted from a dormant server.
  4. Clients rejoin
  5. Bots repopulate
  6. Errors occur

Expected behavior

No errors

thebigsleepjoe commented 6 months ago

That is really odd. It seems that Gmod does not have any error handling for the CreatePlayerBot function when the map/scripts are loaded but no players are connected. I noticed that the function to create a bot isn't actually visible in FP's GitHub repository. I will test this out when I get a minute.

EntranceJew commented 6 months ago

there's a chance that pcall / xpcall / ProtectedCall can still capture it, but i know some things don't

thebigsleepjoe commented 6 months ago

Made a commit to dev branch that should fix this. Pending further testing

thebigsleepjoe commented 6 months ago

Confirmed fixed in dev branch, pending merge to master with v1.2 milestone