The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Max-Max on April 26, 2013, 09:26:28 PM

Title: Fix: NULL pointer call if no road objects where found in PAK
Post by: Max-Max on April 26, 2013, 09:26:28 PM
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?
Title: Re: Fix: NULL pointer call if no road objects where found in PAK
Post by: prissi on April 27, 2013, 07:32:08 AM
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.
Title: Re: Fix: NULL pointer call if no road objects where found in PAK
Post by: Max-Max on April 29, 2013, 11:06:24 PM
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...
Title: Re: Fix: NULL pointer call if no road objects where found in PAK
Post by: prissi on April 30, 2013, 10:29:22 PM
Well, no, it is implemented in wegbauer, which should take care of all ways.
Title: Re: Fix: NULL pointer call if no road objects where found in PAK
Post by: Max-Max on May 01, 2013, 01:19:35 PM
I interpret this as my patch is obsolete now, I'm I right? :)
Title: Re: Fix: NULL pointer call if no road objects where found in PAK
Post by: Dwachs on May 01, 2013, 01:38:33 PM
yes. It served as a trigger to fix this problem nevertheless. :)
Title: Re: Fix: NULL pointer call if no road objects where found in PAK
Post by: Max-Max on May 01, 2013, 04:23:09 PM
Good :)

So this should be moved to resolved bugs then...
Title: Re: Fix: NULL pointer call if no road objects where found in PAK
Post by: IgorEliezer on May 01, 2013, 04:51:29 PM
So we have a happy end. :D