Bug fix for EntityManager

About Artemis

Bug fix for EntityManager

Mensagempor tone » 08 Mai 2013, 11:48

Hi,

I have a bug fix for you for the GetComponent method in artemis_CSharp/Artemis_XNA_INDEPENDENT/Manager/EntityManager.cs
It's a small 4 line cut and paste in your existing code and I'm not familiar at all with Git. Is it ok I submit it this way?

The bug arises when a new ComponentType gets added and the componentsByType bag is at it's size limit. If you're checking for a the presence of the component in one of your systems and it hasn't been added to an entity you get an index out of range error. The fix details (in the GetComponent method)

The lines:
Código: Selecionar todos
if (componentType.Id >= this.componentsByType.Capacity)
{
    return null;
}

need to be moved before the line:
Código: Selecionar todos
Bag<IComponent> bag = this.componentsByType.Get(componentType.Id);


So the full code of the method is now:

Código: Selecionar todos
internal IComponent GetComponent(Entity entity, ComponentType componentType)
{
    Debug.Assert(entity != null, "Entity must not be null.");
    Debug.Assert(componentType != null, "Component type must not be null.");

    if (componentType.Id >= this.componentsByType.Capacity)
    {
        return null;
    }

    int entityId = entity.Id;
    Bag<IComponent> bag = this.componentsByType.Get(componentType.Id);
    if (bag != null && entityId < bag.Capacity)
    {
        return bag.Get(entityId);
    }

    return null;
}
tone
 
Mensagens: 1
Registrado em: 08 Mai 2013, 11:32
Area: Programador

Re: Bug fix for EntityManager

Mensagempor ploobsadmin » 08 Mai 2013, 14:55

hi,
really thanks !!!

I will add this fix asap.
ploobsadmin
Site Admin
 
Mensagens: 17
Registrado em: 07 Abr 2011, 22:39

Re: Bug fix for EntityManager

Mensagempor ploobsadmin » 08 Mai 2013, 17:45

fixed in the main branch.
ploobsadmin
Site Admin
 
Mensagens: 17
Registrado em: 07 Abr 2011, 22:39


Voltar para Artemis C# Entity System

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

cron