def initialize_engine(env_global_config):
    """
    Initialize the engine core. Each process should only have at most one instance of the engine.

    Args:
        env_global_config: the global config.

    Returns:
        The engine.
    """
    # As a workaround, address the potential bug when rendering in headless machine.
    if env_global_config["use_render"] is False and env_global_config["image_observation"] is True:
        _fix_offscreen_rendering()

    cls = BaseEngine
    if cls.singleton is None:
        # assert cls.global_config is not None, "Set global config before initialization BaseEngine"
        cls.singleton = cls(env_global_config)
    else:
        raise PermissionError("There should be only one BaseEngine instance in one process")
    return cls.singleton

    Initialize the engine core. Each process should only have at most one instance of the engine.

    Args:
        env_global_config: the global config.

    Returns:
        The engine.
    
metadrive/engine/engine_utils.py