thegrb93 / StarfallEx

Starfall, but with active development and more features. Write Garry's mod chips similar to E2, but in lua
https://discord.gg/yFBU8PU
Other
198 stars 111 forks source link

instance.player sometimes becomes invalid #1790

Closed legokidlogan closed 2 months ago

legokidlogan commented 3 months ago

timer.simple() inside of the OnEntityCreated hook in the client realm will sometimes error on other players with "Invalid starfall user"

Starfall 'lkl/utility_chips.txt' errored for player Weird_Weirdo
Hook 'onentitycreated' errored with: starfall/libs_sh/timer.lua:118: Invalid starfall user
stack traceback:
    starfall/libs_sh/timer.lua:118: in function 'simple'
    SF:lkl/utility_chips_dir/dup_enhanced_first_person.txt:440: in function <SF:lkl/utility_chips_dir/dup_enhanced_first_person.txt:436>

image

thegrb93 commented 3 months ago

The error you posted indicates that the chip owner was invalid and the script tried to use timer.simple which requires an owner for the timer limit to be checked. It doesn't have anything to do with the timer in the hook call itself.

legokidlogan commented 3 months ago

The chip errored on another player's client, not the owner. I've encountered this at least 30 or so different times now, none of which errored on the owner's client. In all cases, the owner's client instance was perfectly fine.

Furthermore, in all cases both the owner and the player who got the error had been fully spawned into the server for a long time, with the error occurring long after the chip was fully loaded by all clients. Whenever the error occurs, it only happens to one seemingly random player, never multiple at the same time.

ax255 commented 3 months ago

Ive had this happen so many time too, sometime the owner player become invalid for some reason to some clients

thegrb93 commented 3 months ago

The chip errored on another player's client, not the owner. I've encountered this at least 30 or so different times now, none of which errored on the owner's client. In all cases, the owner's client instance was perfectly fine.

Furthermore, in all cases both the owner and the player who got the error had been fully spawned into the server for a long time, with the error occurring long after the chip was fully loaded by all clients. Whenever the error occurs, it only happens to one seemingly random player, never multiple at the same time.

I never said the error happened on the owner; just the error indicates that the owner entity went invalid. You'll have to add checks to your code to check that the owner is valid maybe. If the chip tries to use the owner to increment a limit counter and the owner is invalid, it'll error.

legokidlogan commented 3 months ago

https://github.com/thegrb93/StarfallEx/blob/master/lua/starfall/libs_sh/timer.lua#L78 timer.simple() doesn't use the chip owner for the limit, it uses the local player.

legokidlogan commented 3 months ago

Nevermind, sf stores the owner as instance.player Totally not confusing at all.

legokidlogan commented 3 months ago

Either way, there shouldn't be anything that makes instance.player become invalid in that hook. This issue only started happening recently, sometime around when changes were made to handling full updates and OnRemoved.

Advers commented 2 months ago

I've been getting this error lately too, but it doesn't even come with a stack traceback for me. It's definitely something that started happening more recently. I can't figure out how to reproduce the issue on purpose, but I don't think it's something that can be reliably solved by isValid() checks on the user's part. It just happens.

thegrb93 commented 2 months ago

I wonder if the IsValid() refactor is the cause.

thegrb93 commented 2 months ago

I'll check if the subclass metas get their own IsValid functions or not.

ax255 commented 2 months ago

Been getting those error where player.instance become invalid for about a month

thegrb93 commented 2 months ago

Could see if https://github.com/thegrb93/StarfallEx/pull/1823 fixes it. Idk if the gmod devs have some weird jank where calling the method this way instead of directly would have different behavior.

thegrb93 commented 2 months ago

If not, then I think a gmod update caused the change in behavior of players going invalid.

thegrb93 commented 2 months ago

I'm not merging that btw till it's confirmed to help. Someone needs to check it out.

thegrb93 commented 2 months ago

I think this can be closed now that the error networking is better. If you still find something is wrong feel free to open another.