News:

Congratulations!
 You've won the News Item Lottery! Your prize? Reading this news item! :)

[patch] Remove all references before deleting a factory

Started by Bernd Gabriel, January 01, 2010, 10:10:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bernd Gabriel

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!

Dwachs

Parsley, sage, rosemary, and maggikraut.

Dwachs

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