I found a bug that crashes my game with 50% chance.

Basically what the bug is, for some reason when i create a global variable (In my case it was an Integer), everytime i would end the scene, i had a kind of like reset script that runs along with it too.

from bge import logic as gl

cont = gl.getCurrentController()
own = cont.owner

messages = cont.sensors[“Message”]

objects = gl.getCurrentScene().objects
for mes in messages.bodies:
mes = gl.string2list(mes)

if mes[0] == "Quit" or mes == "Quit":
    gl.Send([7, gl.Username, gl.World])
    gl.WorldPlayerList = []
    gl.World = gl.Username
    gl.superspawn = []

#######################################################
gl.ItemID = 0 #<========== this line crashes my game whenever i change scene or close the game!!!
#######################################################
scenes = gl.getSceneList()
for scene in scenes:
objects = scene.objects
if str(scene) != “World” and str(scene) != “Client_Connection”:
scene.end()
if str(scene) == “World”:
scene.replace(“Option Select”)

I dont know why it crashes my game. Dont ask me how i figured out this problem. All i did was rename the global variable to something else and it stopped the game from crashing.

NOTE: Do not use gl.ItemID as a global variable arrg!!!