Mercurial > fife-parpg
diff clients/editor/plugins/LayerTool.py @ 321:7ddec4ce99b3
Fixed a crash when removing the layer which the editor camera uses
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 16 Aug 2009 21:35:15 +0000 |
parents | 62ec3b530cc6 |
children | 3853f8659598 |
line wrap: on
line diff
--- a/clients/editor/plugins/LayerTool.py Sun Aug 16 20:51:02 2009 +0000 +++ b/clients/editor/plugins/LayerTool.py Sun Aug 16 21:35:15 2009 +0000 @@ -123,12 +123,27 @@ def removeSelectedLayer(self): if not self._mapview: return + if self._mapview.getMap().getNumLayers() <= 1: + print "Can't remove the last layer" + return + layer = self.getActiveLayer() if not layer: return self.select_no_layer() - map = self._mapview.getMap() + map = self._mapview.getMap() + + # FIFE will crash if we try to delete the layer which is in use by a camera + # so we will set the camera to another layer instead + for cam in self._editor.getEngine().getView().getCameras(): + if cam.getLocationRef().getMap().getId() == map.getId(): + if cam.getLocation().getLayer().getId() == layer.getId(): + for l in map.getLayers(): + if l.getId() == layer.getId(): continue + cam.getLocationRef().setLayer(l) + break + map.deleteLayer(layer) self.update(self._mapview)