gigaherz / GraphLib

A simple graph library that is generic but was designed for the use case of assembling block networks in Minecraft Mods
MIT License
8 stars 3 forks source link

Calling Graph.connect using two GraphObjects that don't have a graph set, causes a crash. #4

Closed justliliandev closed 2 years ago

justliliandev commented 2 years ago

This code is executed if both don't have a graph set, indicating that the method should be working with 2 ungraphed GraphObjects

else
{
      target = graphFactory.get();
      if (contextDataFactory != null)
            target.contextData = contextDataFactory.create(target);
}

but this

private void addSingleEdgeInternal(Node<T> node, GraphObject<T> neighbour)
{
    Graph<T> g = neighbour.getGraph();

    if (g == null)
        throw new IllegalArgumentException("The neighbour object is not in a graph.");

crashes. adding this to the first block would fix this, if the crash is not intended behaviour.

target.addNode(object1);
target.addNode(object2);