pokepetter / ursina

A game engine powered by python and panda3d.
https://pokepetter.github.io/ursina/
MIT License
2.23k stars 328 forks source link

Fix race condition #629

Open BurntRanch opened 1 year ago

BurntRanch commented 1 year ago

There is a race condition before the variables are made where the update function runs before the rest of the code is initialized. First, yes, here is proof of the crash. image

Second, CustomFPC is not the reason, this is the code for CustomFPC, it calls super().__init__() which runs FirstPersonController's __init__ function and the rest is handled by FirstPersonController.

class customFPC(FirstPersonController):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
    def input(self, key):
        super().input(key)
        playerID = decodedGameToken[0]
        if playerID in gameState['PLAYERS'] and key == 'left mouse down':
            server.send(server.connections[0], b'FIRE\x00' + serverToken.encode('ascii'))

Last, if setting the self.enabled to False also works, its better to do that, I just couldn't replicate this race condition to test that.