(svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
authorpeter1138
Thu, 01 Feb 2007 01:40:46 +0000
changeset 5889 461a9fbf58da
parent 5888 6fb161a15a3c
child 5890 a5ba89d7f278
(svn r8505) -Codechange: Ensure GRM allocated sprites will be below the original 16384 sprite limit. If not, fail and disable the NewGRF.
src/newgrf.cpp
--- a/src/newgrf.cpp	Wed Jan 31 22:33:24 2007 +0000
+++ b/src/newgrf.cpp	Thu Feb 01 01:40:46 2007 +0000
@@ -2826,6 +2826,16 @@
 						case 0x08: /* General sprites */
 							switch (op) {
 								case 0:
+									/* Check if the allocated sprites will fit below the original sprite limit */
+									if (_cur_spriteid + count >= 16384) {
+										grfmsg(0, "GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
+										SETBIT(_cur_grfconfig->flags, GCF_DISABLED);
+										CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
+
+										_skip_sprites = -1;
+										return;
+									}
+
 									/* 'Reserve' space at the current sprite ID */
 									src1 = _cur_spriteid;
 									_cur_spriteid += count;