{"action":"created","issue":{"url":"https://api.github.com/repos/wesnoth/wesnoth/issues/3042","repository_url":"https://api.github.com/repos/wesnoth/wesnoth","labels_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/3042/labels{/name}","comments_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/3042/comments","events_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/3042/events","html_url":"https://github.com/wesnoth/wesnoth/issues/3042","id":320585140,"number":3042,"title":"Wesnoth crash when units have negative hitpoints: overflow in ai attack calculations","user":{"login":"ePaul","id":645859,"avatar_url":"https://avatars1.githubusercontent.com/u/645859?v=4","gravatar_id":"","url":"https://api.github.com/users/ePaul","html_url":"https://github.com/ePaul","followers_url":"https://api.github.com/users/ePaul/followers","following_url":"https://api.github.com/users/ePaul/following{/other_user}","gists_url":"https://api.github.com/users/ePaul/gists{/gist_id}","starred_url":"https://api.github.com/users/ePaul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ePaul/subscriptions","organizations_url":"https://api.github.com/users/ePaul/orgs","repos_url":"https://api.github.com/users/ePaul/repos","events_url":"https://api.github.com/users/ePaul/events{/privacy}","received_events_url":"https://api.github.com/users/ePaul/received_events","type":"User","site_admin":false},"labels":[{"id":597319005,"url":"https://api.github.com/repos/wesnoth/wesnoth/labels/AI","name":"AI","color":"d455f9","default":false},{"id":35865188,"url":"https://api.github.com/repos/wesnoth/wesnoth/labels/Bug","name":"Bug","color":"fc2929","default":false}],"state":"open","locked":false,"assignee":{"login":"jyrkive","id":1665617,"avatar_url":"https://avatars1.githubusercontent.com/u/1665617?v=4","gravatar_id":"","url":"https://api.github.com/users/jyrkive","html_url":"https://github.com/jyrkive","followers_url":"https://api.github.com/users/jyrkive/followers","following_url":"https://api.github.com/users/jyrkive/following{/other_user}","gists_url":"https://api.github.com/users/jyrkive/gists{/gist_id}","starred_url":"https://api.github.com/users/jyrkive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyrkive/subscriptions","organizations_url":"https://api.github.com/users/jyrkive/orgs","repos_url":"https://api.github.com/users/jyrkive/repos","events_url":"https://api.github.com/users/jyrkive/events{/privacy}","received_events_url":"https://api.github.com/users/jyrkive/received_events","type":"User","site_admin":false},"assignees":[{"login":"jyrkive","id":1665617,"avatar_url":"https://avatars1.githubusercontent.com/u/1665617?v=4","gravatar_id":"","url":"https://api.github.com/users/jyrkive","html_url":"https://github.com/jyrkive","followers_url":"https://api.github.com/users/jyrkive/followers","following_url":"https://api.github.com/users/jyrkive/following{/other_user}","gists_url":"https://api.github.com/users/jyrkive/gists{/gist_id}","starred_url":"https://api.github.com/users/jyrkive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyrkive/subscriptions","organizations_url":"https://api.github.com/users/jyrkive/orgs","repos_url":"https://api.github.com/users/jyrkive/repos","events_url":"https://api.github.com/users/jyrkive/events{/privacy}","received_events_url":"https://api.github.com/users/jyrkive/received_events","type":"User","site_admin":false}],"milestone":null,"comments":9,"created_at":"2018-05-06T11:38:31Z","updated_at":"2018-05-09T17:38:23Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I'm running v1.14.0+dev (43f30cdd613-Clean) (self-compiled), with the UMC \"A troop in a war\". Somehow I got enemy units with negative hitpoints (which is likely [a bug in that addon](https://forums.wesnoth.org/viewtopic.php?f=8&t=41451&p=627469#p627469)), but then Wesnoth simply crashes without any indication why.\r\n\r\n**Reproduction**\r\n\r\n* (possibly: install \"A troop in a war\" 0.1.6d, not sure if this is needed for reproducing.)\r\n* Load this savegame [AG-Skirmish Runde 3-c.gz](https://github.com/wesnoth/wesnoth/files/1977548/AG-Skirmish.Runde.3-c.gz)\r\n* Click \"End turn\".\r\n→ Wesnoth crashes (window disappears, exit code 134).\r\n\r\nThe following is printed on the console (stdout/stderr):\r\n\r\n```\r\nBattle for Wesnoth v1.14.0+dev (43f30cdd613-Clean)\r\nStarted on Sun May  6 12:43:29 2018\r\n\r\nAutomatically found a possible data directory at /home/USER/projektoj/wesnoth\r\n\r\nData directory:               /home/USER/projektoj/wesnoth\r\nUser configuration directory: /home/USER/.config/wesnoth\r\nUser data directory:          /home/USER/.local/share/wesnoth/1.14\r\nCache directory:              /home/USER/.cache/wesnoth\r\n\r\nSetting mode to 1920x1026\r\nChecking lua scripts... ok\r\n20180506 12:43:36 error display: Tile at 16,7 isn't on the map, can't scroll to the tile.\r\n20180506 12:43:40 warning ai/general: overflow in ai attack calculation\r\n20180506 12:43:40 warning ai/general: overflow in ai attack calculation\r\n20180506 12:43:40 warning ai/general: overflow in ai attack calculation\r\n20180506 12:43:40 warning ai/general: overflow in ai attack calculation\r\n[... some thousand more of those lines ...]\r\n20180506 12:43:40 warning ai/general: overflow in ai attack calculation\r\n20180506 12:43:40 warning ai/general: overflow in ai attack calculation\r\n20180506 12:43:40 warning ai/general: overflow in ai attack calculation\r\nwesnoth: src/attack_prediction.cpp:1764: double {anonymous}::calculate_probability_of_debuff(double, bool, double, double, bool, double): Assertion `initial_prob >= 0.0 && initial_prob <= 1.0' failed.\r\nAbgebrochen (Speicherabzug geschrieben)\r\n```\r\n\r\n(I didn't find the mentioned core dump, not sure where that would be.)\r\n\r\n**Expected behavior**\r\nIf WML content creates an invalid state, Wesnoth should show a useful error message, and potentially go back to the main screen, not simply crash."},"comment":{"url":"https://api.github.com/repos/wesnoth/wesnoth/issues/comments/387817309","html_url":"https://github.com/wesnoth/wesnoth/issues/3042#issuecomment-387817309","issue_url":"https://api.github.com/repos/wesnoth/wesnoth/issues/3042","id":387817309,"user":{"login":"jyrkive","id":1665617,"avatar_url":"https://avatars1.githubusercontent.com/u/1665617?v=4","gravatar_id":"","url":"https://api.github.com/users/jyrkive","html_url":"https://github.com/jyrkive","followers_url":"https://api.github.com/users/jyrkive/followers","following_url":"https://api.github.com/users/jyrkive/following{/other_user}","gists_url":"https://api.github.com/users/jyrkive/gists{/gist_id}","starred_url":"https://api.github.com/users/jyrkive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyrkive/subscriptions","organizations_url":"https://api.github.com/users/jyrkive/orgs","repos_url":"https://api.github.com/users/jyrkive/repos","events_url":"https://api.github.com/users/jyrkive/events{/privacy}","received_events_url":"https://api.github.com/users/jyrkive/received_events","type":"User","site_admin":false},"created_at":"2018-05-09T17:38:22Z","updated_at":"2018-05-09T17:38:22Z","author_association":"MEMBER","body":"All right, debugging shows why exactly negative HP ends up triggering this assertion.\r\n\r\n[Omae wa mou shindeiru](http://knowyourmeme.com/memes/you-are-already-dead-omae-wa-mou-shindeiru).\r\n\r\nIn this savegame, the AI simulates a situation where unit A attacks unit B. Unit B has a poisoning attack, but its HP is negative. Meanwhile, unit A is so close to level-up that killing unit B will level up unit A and heal the poison status. Damage calculation takes both the poisoning attack and the upcoming level-up into account when calculating the probability that unit A will be poisoned after the attack.\r\n\r\nThe problem is that due to the negative HP, damage calculation code thinks that B is already dead before the fight (HP <= 0), but that B may not be dead after the fight (HP == 0). Thus, the probability that A kills B is considered to be **negative**, and the fact that killing B heals poison is considered to **increase** the probability that A is poisoned after the fight. Thus, the \"A is poisoned\" probability creeps to 105 %, which causes the crash if the AI simulates another fight for A after this one.\r\n\r\nNext, time to start writing the fix..."}}
{"actor":{"display_login":"jyrkive"}}