The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Bernd Gabriel on January 01, 2010, 10:10:29 pm

Title: [patch] Remove all references before deleting a factory
Post by: Bernd Gabriel on January 01, 2010, 10:10:29 pm
ai_goods_t holds several references to factories (fabrik_t objects). If player 'public service' removes a factory invalid pointers in ai_goods remain. Saving such a game may work, but produces invalid coordinates. Loading such a game produces NULL pointers in ai_goods_t. The next attempt to save this game crashes because of these NULL pointers.

This patch cleans up ai_goods_t before a factory is deleted and checks, whether loaded forbidden_connections contain valid data. Invalid data is ignored, which is safe for game play as such no longer existing connections won't be checked again at all.

How it works:
- hausbauer_t calls the new method spieler_t::notification(notification_t info, fabrik_t &fab) to inform the players, that a fab is going to be deleted.
- enum notification_t is declared in new header file utils/notification.h
- TODO(?): I'm not sure, what ai_goods_t must and/or should do in states NR_*_SUCCESS.
  - Just skip the message, as everythings should have been done automatically by hausbauer_t?
  - Undo the whole new convoys and ways etc.?

BTW: The use of more (overloaded) methods notification() can help to solve analog referencing problems as well.
Title: Re: [patch] Remove all references before deleting a factory
Post by: Dwachs on January 02, 2010, 12:56:41 pm
thank you.
Title: Re: [patch] Remove all references before deleting a factory
Post by: Dwachs on January 20, 2010, 07:58:22 pm
incorporated in 3044. I hope I did not break your implementation..