Bernd,
thank you for spotting that - I have fixed it now. Bizarrely, however, that does not fix the problem with loading things from line management. I have narrowed down the problem, which is proving most intractable. The error occurs in this part of linemanagement.cc:
sint32 totalLines = 0;
file->rdwr_long(totalLines, " ");
DBG_MESSAGE("simlinemgmt_t::rdwr()","number of lines=%i",totalLines);
for (int i = 0; i<totalLines; i++) {
simline_t::linetype lt=simline_t::line;
file->rdwr_enum(lt, "\n");
simline_t * line;
switch(lt) {
case simline_t::truckline: line = new truckline_t( welt, sp); break;
case simline_t::trainline: line = new trainline_t( welt, sp); break;
case simline_t::shipline: line = new shipline_t( welt, sp); break;
case simline_t::airline: line = new airline_t( welt, sp); break;
case simline_t::monorailline: line = new monorailline_t(welt, sp); break;
case simline_t::tramline: line = new tramline_t( welt, sp); break;
case simline_t::maglevline: line = new maglevline_t( welt, sp); break;
case simline_t::narrowgaugeline:line = new narrowgaugeline_t(welt, sp); break;
default:
// line = new simline_t( welt, sp); break;
dbg->fatal( "simlinemgmt_t::create_line()", "Cannot create default line!" );
}
line->rdwr(file);
add_line( line->get_handle() );
The problem occurs here and only here: games so old that they do not have any "linemanagement" parts to their saves (from 2007 and earlier) load without problem, so there is no generalised corruption on loading.
The second value loaded in the line file->rdwr_enum(lt, "\n"); (in other words, the second time that that method is called, whenever i is 1) is always loaded as 0 (translated to the appropriate enum, "line") rather than the correct value, which then triggers the "invalid line" error message provided for further down in the code. The problem does not appear to be a general problem with the rdwr_enum method, since that method is used in many other places in the load/save code that all appear to work correctly when loading a very old saved game.
The problem is not a problem with saving, since I tested using a saved game from the latest nightly of Simutrans-Standard, which I had created with two lines specifically for the purpose. In Simutrans-Standard, the second value is read correctly as 2 (rail), but in Simutrans-Experimental, it is read incorrectly as 0 (invalid).
The code section reproduced above is identical both to its equivalent in the latest version of Simutrans-Standard, and the known good version in Simutrans-Experimental 7.0, so no change to that code can account for the problem.
Any help on solving this Alice in Wonderland riddle would be very much appreciated.