Index: clear_cmd.c
===================================================================
--- clear_cmd.c	(revision 650)
+++ clear_cmd.c	(working copy)
@@ -91,6 +91,18 @@
 	
 	if ((_map_type_and_height[tile] >> 4) == MP_RAILWAY) {
 		static const byte _railway_modes[4] = {8, 0x10, 4, 0x20};
+		static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb};
+
+		// Nothing could be built at the steep slope - this avoids a bug
+		// when you have a single diagonal track in one corner on a
+		// basement and then you raise the other corner.
+		if ((GetTileSlope(tile, NULL)&0xF) == _railway_dangslopes[mode]) {
+			_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
+			return -1;
+		}
+
+		// If we have a single diagonal track there, the other side of
+		// tile can be terraformed.
 		if ((_map5[tile]&~0x40) == _railway_modes[mode])
 			return 0;
 	}
