Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Unity crashes when new generic SystemBase is created while there are already 1024 systems

Discussion in 'Entity Component System' started by DreamingImLatios, Jun 4, 2023.

  1. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,217
    Don't ask me how or why I found this.

    But if you call TypeManager.GetSystemTypeIndex(System.Type) and pass in a concrete generic type it has never seen before, and then get a type index of 1024, if you then try to create an instance of that system, Unity will hard crash.

    The reason for this is that adding the type will cause the UnsafeLists in TypeManager to resize. However, the shared statics store pointers to the underlying memory of those UnsafeLists, meaning that the shared statics are now pointing to garbage memory.