Skip to main content
Topic: [patch] Remove all references before deleting a factory (Read 4880 times) previous topic - next topic

[patch] Remove all references before deleting a factory

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.
The journey is the reward!

Re: [patch] Remove all references before deleting a factory

Reply #1
thank you.
Parsley, sage, rosemary, and maggikraut.

Re: [patch] Remove all references before deleting a factory

Reply #2
incorporated in 3044. I hope I did not break your implementation..
Parsley, sage, rosemary, and maggikraut.