Doesn't really fix anything but it was causing a couple bugs when I created a couple CGameWorlds. Entities should work only in the CGameWorld they were created in anyway.
The change is originally by @heinrich5991, I also included the 2 helper functions but they are unused in teeworlds. I could remove those if you prefer.