Merge lp:~widelands-dev/widelands/bug-1638280-coroutine-messages into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8745
Proposed branch: lp:~widelands-dev/widelands/bug-1638280-coroutine-messages
Merge into: lp:widelands
Diff against target: 33 lines (+11/-4)
1 file modified
src/logic/cmd_luacoroutine.cc (+11/-4)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1638280-coroutine-messages
Reviewer Review Type Date Requested Status
Notabilis Approve
Review via email: mp+349058@code.launchpad.net

Commit message

Do not broadcast Lua coroutine error messages to empty player slots. Also, use richtext_escape on them.

Description of the change

To reproduce the crash, add an unused ware to a prefilled building in a starting condition and close a player slot.

With the changes in this branch, players should get a coroutine error message instead of a crash.

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

Continuous integration builds have changed state:

Travis build 3628. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/400902520.
Appveyor build 3427. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1638280_coroutine_messages-3427.

Revision history for this message
Notabilis (notabilis27) wrote :

Worked fine when testing, thanks.

Two comments regarding the code:
1) Maybe move richtext_escape() in front of the loop?
2) Maybe only create msg if we already know that the player is in use, e.g., move if(!recipient)continue; to the top of the loop.

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

I have implemented both suggestions, thanks!

@bunnybot merge

Revision history for this message
Notabilis (notabilis27) wrote :

Uh... from the diff it seems as if error_message is inside the for-loop. Is this intentional?

Revision history for this message
GunChleoc (gunchleoc) wrote :

Duh. Thanks for having my back.

Revision history for this message
Notabilis (notabilis27) wrote :

You're welcome, looking better now. :)

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3649. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/401502950.
Appveyor build 3448. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1638280_coroutine_messages-3448.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/cmd_luacoroutine.cc'
2--- src/logic/cmd_luacoroutine.cc 2018-05-05 17:10:37 +0000
3+++ src/logic/cmd_luacoroutine.cc 2018-07-08 18:38:45 +0000
4@@ -23,6 +23,7 @@
5
6 #include "base/log.h"
7 #include "base/macros.h"
8+#include "graphic/text_layout.h"
9 #include "io/fileread.h"
10 #include "io/filewrite.h"
11 #include "logic/game.h"
12@@ -50,11 +51,17 @@
13 log("Error in Lua Coroutine\n");
14 log("%s\n", e.what());
15 log("Send message to all players and pause game\n");
16+ const std::string error_message = richtext_escape(e.what());
17 for (int i = 1; i <= game.map().get_nrplayers(); i++) {
18- std::unique_ptr<Message> msg(new Widelands::Message(
19- Message::Type::kGameLogic, game.get_gametime(), "Coroutine",
20- "images/ui_basic/menu_help.png", "Lua Coroutine Failed", e.what()));
21- game.get_player(i)->add_message(game, std::move(msg), true);
22+ // Send message only to open player slots
23+ Player* recipient = game.get_player(i);
24+ if (recipient) {
25+ std::unique_ptr<Message> msg(new Widelands::Message(
26+ Message::Type::kGameLogic, game.get_gametime(), "Coroutine",
27+ "images/ui_basic/menu_help.png", "Lua Coroutine Failed", error_message));
28+
29+ recipient->add_message(game, std::move(msg), true);
30+ }
31 }
32 game.game_controller()->set_desired_speed(0);
33 }

Subscribers

People subscribed via source and target branches

to status/vote changes: