Browse code

Automapping: Handle non existing input layers in working map.

If there is an input layer required by the rule map, which does not
exist in the working map, the rules will not get applied, as the rules
are not met.

Before there was no check if input layers existed, so you could crash
tiled.

Thanks to Giancarlo Todone for spotting the bug.

Fixes #219

Stefan Beller authored on 09/06/2012 08:11:55
Showing 1 changed files
... ...
@@ -544,14 +544,18 @@ QRect AutoMapper::applyRule(const int ruleIndex, const QRect &where)
544 544
             const InputIndex &ii = mInputRules[index];
545 545
 
546 546
             bool allLayerNamesMatch = true;
547
-            foreach (const QString &name, mInputRules[index].names) {
548
-                const int index = mMapWork->indexOfLayer(name,
549
-                                                         Layer::TileLayerType);
550
-                const TileLayer *setLayer = mMapWork->layerAt(index)->asTileLayer();
551
-                allLayerNamesMatch &= compareLayerTo(setLayer,
552
-                                                     ii[name].listYes,
553
-                                                     ii[name].listNo,
554
-                                                     ruleInput, QPoint(x, y));
547
+            foreach (const QString &name, ii.names) {
548
+                const int i = mMapWork->indexOfLayer(name, Layer::TileLayerType);
549
+                if (i == -1) {
550
+                    allLayerNamesMatch = false;
551
+                } else {
552
+                    const TileLayer *setLayer = mMapWork->layerAt(i)->asTileLayer();
553
+                    allLayerNamesMatch &= compareLayerTo(setLayer,
554
+                                                         ii[name].listYes,
555
+                                                         ii[name].listNo,
556
+                                                         ruleInput,
557
+                                                         QPoint(x, y));
558
+                }
555 559
             }
556 560
             if (allLayerNamesMatch) {
557 561
                 anymatch = true;