changeset 16208:bd3841c2874e draft

(svn r20908) -Fix [FS#4156]: assertion when the buy menu graphics callback accessed a variable that needs a tile index
author rubidium <rubidium@openttd.org>
date Fri, 08 Oct 2010 21:07:54 +0000
parents e4c88897ae68
children f94968aadc35
files src/newgrf_object.cpp
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -241,6 +241,7 @@
 			/* Allow these, but find the closest town. */
 			case 0x45:
 			case 0x46:
+				if (!IsValidTile(tile)) goto unhandled;
 				t = ClosestTownFromTile(tile, UINT_MAX);
 				break;
 
@@ -257,11 +258,11 @@
 			 * 0x63: Animation counter of nearby tile, see above.
 			 */
 			default:
-				DEBUG(grf, 1, "Unhandled object property 0x%X", variable);
+				goto unhandled;
+		}
 
-				*available = false;
-				return UINT_MAX;
-		}
+		/* If there's an invalid tile, then we don't have enough information at all. */
+		if (!IsValidTile(tile)) goto unhandled;
 	} else {
 		t = o->town;
 	}
@@ -313,6 +314,7 @@
 		case 0x64: return GetCountAndDistanceOfClosestInstance(parameter, object->grffile->grfid, tile, o);
 	}
 
+unhandled:
 	DEBUG(grf, 1, "Unhandled object property 0x%X", variable);
 
 	*available = false;