tzachshabtay / MonoAGS

AGS (Adventure Game Studio) reimagined in Mono
https://tzachshabtay.github.io/MonoAGS/
Artistic License 2.0
27 stars 8 forks source link

Exception in RenderOrderSelector when comparing child object with "orphan" object #269

Closed ghost closed 6 years ago

ghost commented 6 years ago

Steps to reproduce: Create three objects - A, B, C:

Result: upon running the room engine will throw System.NullReferenceException, stack trace:

Basically, what happens is that object with parent is compared with another object which has no parent and is not the parent nor child of the first object.

This code:

                IObject newParent1 = getNewParent(parent1, s1);
                IObject newParent2 = getNewParent(parent2, s2);
                if (newParent1 != newParent2)
                {
                    float result = compareObj(newParent1, newParent2); <------ crashes here
                    if (result != 0f) return result;
                }
                if (newParent1 == null || newParent2 == null || (newParent1 == s1 && newParent2 == s2))
                {
                    //Trying to avoid ambiguity, so using X as a last resort
                    return getX(s2) - getX(s1);
                }