bugFreeciv - Bugs: bug #18461, crash using lua function civil_war...

Show feedback again

bug #18461: crash using lua function civil_war (in ai_plr_data_get() [aidata.c::310]: assertion 'ai->phase_initialized' failed.)

Submitted by:  Matthias Pfafferodt <syntron>
Submitted on:  Sat Aug 6 22:34:57 2011  
Category: aiSeverity: 3 - Normal
Priority: 5 - NormalStatus: Duplicate
Assigned to: Marko Lindqvist <cazfi>Open/Closed: Closed
Release: 2.3.99 (svn20069)Operating System: None
Planned Release: 2.5.0, 2.6.0, 3.0.0Contains string changes: None

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


(Jump to the original submission Jump to the original submission)

Tue Jan 20 23:18:01 2015, comment #8:

At least the exact stack trace here won't happen any more.

ai_goldequiv_clause() is able to handle the situation where data phase is not already open (it uses 'bool close' pointer feature of the dai_plr_data_get())

Marko Lindqvist <cazfi>
Project AdministratorIn charge of this item.
Wed Aug 10 06:19:38 2011, comment #7:

I'm not 100% sure about the patch - can't be as I did only test my error case. Here it did remove the crash and, furthermore, did not add any other. As I see it the following work flow is done:

- begin_turn()
-- new initialisation to ai/adv phase
- loop (phases)
-- begin_phases()
--- initialisation to ai/adv phase; if initialised, do nothing
-- (some code)
-- end_phase()
--- end of ai/adv phase
- end (loop phases)
- end_turn()
-- in this function the ai/adv phase can be closed to have the correct count of begin/end; these functions will do nothing at the moment but as you said, would be helpful to read the code

Matthias Pfafferodt <syntron>
Project Member
Tue Aug 9 21:13:09 2011, comment #6:

Are you sure about the patch? Just by reading it (without checking from source code more context) I notice that you add initialization to one place, but don't remove it from anywhere. Isn't this going to cause double initialization? (If it is, and you have tested this patch without error messages, we are missing important assert)
Also, I don't remember offhand what, but moving the initialization earlier from where it is may cause other problems (I recall that when I last moved it, I put it as early as possible) Some information that it uses is bogus earlier, or something like that. Code comments or old tickets hopefully contain more exact information.

Marko Lindqvist <cazfi>
Project AdministratorIn charge of this item.
Tue Aug 9 21:01:27 2011, comment #5:

I did read bug #18333 and at least the reason I found is similar. The signal 'turn_started' is called in begin_turn. At that time ai/adv phase is not open for any player. It is initialised in begin_phase() in srv_running(). It crashs on contact to a player which exists before (the new player has the phases initialised).

I did not test any other but the default phase setting. I I remember correctly I never did test the different possibilities of this setting.

Matthias Pfafferodt <syntron>
Project Member
Tue Aug 9 18:46:36 2011, comment #4:

Is civil war another case where phasemode != simultaneous would cause problems as described in bug #18333?

Marko Lindqvist <cazfi>
Project AdministratorIn charge of this item.
Tue Aug 9 18:12:43 2011, comment #3:

I did some tests and I do use a unique setting: civil_war() is called via the lua signal 'turn_started'. At the time this signal is raised, neither the advisor nor the AI are initialized. Thus the core dump. The attached patch fixes the error by doing the initialization before ...

Please test ...

(file #13791)

Matthias Pfafferodt <syntron>
Project Member
Tue Aug 9 09:02:02 2011, comment #2:

Oh, rats.
(Doesn't civil_war() execute mid-turn when you trigger it by taking over a city? Is that already dealt with?)

Jacob Nevins <jtn>
Project Administrator
Tue Aug 9 06:06:43 2011, comment #1:

civil_war() was designed to be called during turn change (ai phase for all players). Now, it can be executed via a lua function at any time. Thus, the ai phase does not have to be initialized. One possible solution would be to check for this if a civil war occurs. Thus, the ai phase would be initialized for all players, the civil war executed, and after that the ai phase would be closed. Thoughts?

Matthias Pfafferodt <syntron>
Project Member
Sat Aug 6 22:34:57 2011, original submission:

I'm working on a lua test game. Trying to add the lua function civil_war() I got the following core dump:

The attached savegame can be used to reproduce it. Simply start freeciv as './ser -F -f luatest.sav' and enter start ...

Matthias Pfafferodt <syntron>
Project Member


(Note: upload size limit is set to 1024 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #13763:  luatest.sav added by syntron (38kB - application/x-spss-sav)


Depends on the following items: None found

Items that depend on this one

   patch dependencies.


Carbon-Copy List
  • -unavailable- added by cazfi (Posted a comment)
  • -unavailable- added by jtn (Posted a comment)
  • -unavailable- added by syntron (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Error: not logged in



    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue Jan 20 23:18:01 2015cazfiStatusIn Progress=>Duplicate
    Sun Jan 4 07:49:03 2015cazfiAssigned toNone=>cazfi
      Planned Release2.4.0=>2.5.0, 2.6.0, 3.0.0
    Wed Aug 10 06:19:38 2011syntronStatusReady For Test=>In Progress
    Tue Aug 9 18:12:43 2011syntronAttached File-=>Added 20110808-48-initialize-advisor-and-AI-code-before-lua-signal-tur.patch, #13791
      StatusNone=>Ready For Test
    Sat Aug 6 22:34:57 2011syntronAttached File-=>Added luatest.sav, #13763
    Show feedback again

    Back to the top

    Powered by Savane 3.1-cleanup