News:

SimuTranslator
Make Simutrans speak your language.

Fix: NULL pointer call if no road objects where found in PAK

Started by Max-Max, April 26, 2013, 09:26:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Max-Max

Hi,

I ran into this crash when I experimented with the minimum PAK file setup.
If no road objects are present in the pak, wegbauer_t::get_earliest_way will return a NULL pointer and calls a member function without checking the pointer.

game_start = max( game_start, (wegbauer_t::get_earliest_way(road_wt)->get_intro_year_month()+11)/12 );

I have no idea what exit code to use, but the magic number 11 was used earlier in a similar situation.

Just because a PAK file with a given filename exists and loads, doesn't mean that all vital objects are included in it.
Without knowing to much about the code, the test should probably be done already after all PAK files has been loaded and all vital object should be tested, not only the filenames. I'm I right?
- My code doesn't have bugs. It develops random features...

prissi

A minimum pak must contain a road, otherwise it cannot generate cities. A random road is a requirement for a minimum pak. That should generate a meaningful fatal error indeed.

Max-Max

Yes, that was the question I raised. A PAK should have at least one road but as long users are compiling thir own PAKs it is not guaranteed that everything that is needed is there.

In these cases a message should state what object is missing instead of crash.

I think the best approach would be to first load all PAK files then , in one place, check if all vital objects has been loaded and present a list of missing objects. This would help newcomers, as myself, a lot.

I saw a note in rev 6475 SVN log "Warning message when no default road is found". I interpret this as the implemented version of this path...
- My code doesn't have bugs. It develops random features...

prissi

Well, no, it is implemented in wegbauer, which should take care of all ways.

Max-Max

I interpret this as my patch is obsolete now, I'm I right? :)
- My code doesn't have bugs. It develops random features...

Dwachs

yes. It served as a trigger to fix this problem nevertheless. :)
Parsley, sage, rosemary, and maggikraut.

Max-Max

Good :)

So this should be moved to resolved bugs then...
- My code doesn't have bugs. It develops random features...