Merge lp:~widelands-dev/widelands/fix_economy_crash into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 8247
Proposed branch: lp:~widelands-dev/widelands/fix_economy_crash
Merge into: lp:widelands
Diff against target: 127 lines (+50/-39)
1 file modified
data/campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua (+50/-39)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fix_economy_crash
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+315284@code.launchpad.net

Commit message

Generalize waiting on a window to be opened and a tab to be selected.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1835. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/193891633.
Appveyor build 1673. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_fix_economy_crash-1673.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Not tested, code LGTM

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

Tested,the crash is gone.

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua'
2--- data/campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua 2016-12-28 22:11:45 +0000
3+++ data/campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua 2017-01-20 21:53:31 +0000
4@@ -10,6 +10,31 @@
5 burn_tavern_down()
6 end
7
8+function wait_for_window_and_tab_or_complain(
9+ window_name,
10+ tab_name,
11+ objective, complain_msg
12+)
13+ while true do
14+ -- This waits for the window to be opened.
15+ if not mv.windows[window_name] then
16+ objective.visible = true
17+ message_box_objective(plr, complain_msg)
18+ while not mv.windows[window_name] do sleep(200) end
19+ objective.visible = false
20+ end
21+
22+ -- But it might be closed at any point in time. If it is open and the
23+ -- correct tab is active, we terminate the loop.
24+ if mv.windows[window_name] and
25+ mv.windows[window_name].tabs[tab_name].active
26+ then
27+ break
28+ end
29+ sleep(200)
30+ end
31+end
32+
33 function burn_tavern_down()
34 sleep(500)
35 scroll_to_field(tavern_field)
36@@ -26,17 +51,11 @@
37 -- We cannot create several objectives with the same name. Therefore, we create o2 here once and change its visibility
38 local o2 = add_campaign_objective(reopen_building_stat_obj)
39 o2.visible = false
40- local medium_tab_active = false
41- while not medium_tab_active do
42- if not mv.windows.building_statistics then
43- o2.visible = true
44- message_box_objective(plr, reopen_building_stat)
45- while not mv.windows.building_statistics do sleep(200) end
46- o2.visible = false
47- end
48- if mv.windows.building_statistics.tabs["building_stats_medium"].active then medium_tab_active = true end
49- sleep(200)
50- end
51+ wait_for_window_and_tab_or_complain(
52+ "building_statistics",
53+ "building_stats_medium",
54+ o2, reopen_building_stat
55+ )
56 while mv.windows.building_statistics do sleep(100) end
57 set_objective_done(o, 0)
58
59@@ -45,18 +64,16 @@
60 set_objective_done(o, wl.Game().real_speed)
61
62 o = message_box_objective(plr, inventory2)
63- -- We cannot create several objectives with the same name. Therefore, we create o2 here once and change its visibility
64+ -- We cannot create several objectives with the same name. Therefore, we
65+ -- create o2 here once and change its visibility
66 o2 = add_campaign_objective(reopen_stock_menu_obj)
67 o2.visible = false
68- while not mv.windows.stock_menu.tabs["wares_in_warehouses"].active do
69- if not mv.windows.stock_menu then
70- o2.visible = true
71- message_box_objective(plr, reopen_stock_menu)
72- while not mv.windows.stock_menu do sleep(200) end
73- o2.visible = false
74- end
75- sleep(200)
76- end
77+
78+ wait_for_window_and_tab_or_complain(
79+ "stock_menu",
80+ "wares_in_warehouses",
81+ o2, reopen_stock_menu
82+ )
83 set_objective_done(o, 0)
84 message_box_objective(plr, inventory3)
85
86@@ -83,29 +100,23 @@
87 o = message_box_objective(plr, ware_stats2)
88 local o2 = add_campaign_objective(reopen_ware_stats1_obj)
89 o2.visible = false
90- while not mv.windows.ware_statistics.tabs["economy_health"].active do
91- if not mv.windows.ware_statistics then
92- o2.visible = true
93- message_box_objective(plr, reopen_ware_stats1)
94- while not mv.windows.ware_statistics do sleep(200) end
95- o2.visible = false
96- end
97- sleep(200)
98- end
99+
100+ wait_for_window_and_tab_or_complain(
101+ "ware_statistics",
102+ "economy_health",
103+ o2, reopen_ware_stats1
104+ )
105 set_objective_done(o, 0)
106
107 o = message_box_objective(plr, ware_stats3)
108 o2 = add_campaign_objective(reopen_ware_stats2_obj)
109 o2.visible = false
110- while not mv.windows.ware_statistics.tabs["stock"].active do
111- if not mv.windows.ware_statistics then
112- o2.visible = true
113- message_box_objective(plr, reopen_ware_stats2)
114- while not mv.windows.ware_statistics do sleep(200) end
115- o2.visible = false
116- end
117- sleep(200)
118- end
119+
120+ wait_for_window_and_tab_or_complain(
121+ "ware_statistics",
122+ "stock",
123+ o2, reopen_ware_stats2
124+ )
125 set_objective_done(o, 0)
126
127 o = message_box_objective(plr, ware_stats4)

Subscribers

People subscribed via source and target branches

to status/vote changes: