Repository: movingblocks/terasology
Issue: StackOverflow in NUI editor when setting to 2 items to be on top of each other

<!-- Thanks for taking the time to submit a thorough issue report for Terasology! :-)
Please fill out whichever details below seem relevant to your issue.
Note that suggestions, general questions & support should go in the forum:
* http://forum.terasology.org/forum/suggestions.21
* http://forum.terasology.org/forum/support.20/
Bug reports and crashes likely resulting from bugs in the engine go here on GitHub. -->

### What you were trying to do

When using the NUI editor, had an item with its position-bottom target set to TOP and widget to the id of the second item.
Then accidentally set the second item's position-top target set to TOP and widget to the id of the first item.
### What actually happened

A StackOverflow error is thrown, and everytime the NUI Editor is launched the exception is thrown again. Probably because when throwing the exception the file is auto-saved then when relaunching the editor it loads the auto-save and the exception is thrown again.

### How to reproduce

* Create a new screen in the NUI Editor
* Add 2 UILabels (for example, but probably can be done with anything)
* Add a position-bottom to the first UILabel. Set its widget value to the id of the second UILabel, and its target to TOP
* Add a position-top to the second UILabel. Set its widget value to the id of the first UILabel
### Log details, and UI code

[Terasology Menu Log](https://github.com/MovingBlocks/Terasology/files/702622/Terasology-menu.log.txt)

And the UI where it occured.
```json
{
  "selectedAsset": "New Screen",
  "editorContents": {
    "type": "PlaceholderScreen",
    "skin": "engine:default",
    "contents": {
      "type": "RelativeLayout",
      "contents": [
        {
          "type": "UILabel",
          "id": "sampleLabel",
          "layoutInfo": {
            "width": 500,
            "position-horizontal-center": {},
            "position-vertical-center": {},
            "position-bottom": {
              "widget": "newWidget",
              "target": "TOP"
            }
          },
          "text": "Welcome to the Terasology NUI editor!\\r\\nVisit https://github.com/Terasology/TutorialNui/wiki for a quick overview of the editor,\\r\\nas well as the NUI framework itself."
        },
        {
          "type": "engine:UILabel",
          "id": "newWidget",
          "layoutInfo": {
            "position-top": {
              "target": "TOP",
              "widget": "sampleLabel"
            }
          }
        }
      ]
    }
  }
}
```

Changed files:
engine/src/main/java/org/terasology/rendering/nui/layouts/relative/RelativeLayout.java

diff --git a/engine/src/main/java/org/terasology/rendering/nui/layouts/relative/RelativeLayout.java b/engine/src/main/java/org/terasology/rendering/nui/layouts/relative/RelativeLayout.java
index 1a93c0ea9..340896884 100644
--- a/engine/src/main/java/org/terasology/rendering/nui/layouts/relative/RelativeLayout.java
+++ b/engine/src/main/java/org/terasology/rendering/nui/layouts/relative/RelativeLayout.java
@@ -190,9 +190,13 @@ private Rect2i getTargetRegion(String id, Canvas canvas) {
             }
             WidgetInfo target = contentLookup.get(id);
             if (target != null) {
-                Rect2i region = getRegion(target, canvas);
-                loopDetectionId = "";
-                return region;
+                try {
+                    Rect2i region = getRegion(target, canvas);
+                    loopDetectionId = "";
+                    return region;
+                } catch (StackOverflowError e){
+                    logger.error("Stack Overflow detected resolving layout of element {}, unable to render", loopDetectionId);
+                }
             }
         }
         loopDetectionId = "";