[harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
WhiteWolf
Forum Moderator
Posts: 654
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

[harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by WhiteWolf »

Hello,

I spotted a rather mysterious Lua error message concerning a [harm_unit] action. Here is a screenshot of the error:
ezmegmi.png
And here is the [harm_unit] that definitely fired just before this occured:

Code: Select all

[harm_unit]
	[filter]
		[not]
			id=player_lead,ai_lead
		[/not]
		[not]
			[filter_location]
				terrain=Ftf,*^V*
			[/filter_location]
		[/not]
	[/filter]
	delay=0
	amount=4
	kill=yes
	fire_event=no
	animate=no
	experience=no
[/harm_unit]
player_lead, and ai_lead are existing leader units at the time. Ftf is an existing custom location.
The action is supposed to harm every unit that is not the leaders and are not standing in villages or in Ftf. And usually it does it perfectly.
This is Wesnoth 1.14.5 on Debian.
That's all I'm afraid. This event happens every turn (turn refresh), and there weren't any issues with it ever, nor have been since... so this only happened once. But it did, so it potentially can again. What could this be? (can it be related to me using still 1.14.5...?)

Thanks
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
Ravana
Forum Moderator
Posts: 2457
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by Ravana »

Error message gives line 163, which just accesses unit location. Before that there is some logic about poisoned/slowed/petrified/unhealable status.
User avatar
josteph
Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by josteph »

@WhiteWolf If you have a savefile that reproduces this, feel free to upload it, that might help someone figure it out.
User avatar
WhiteWolf
Forum Moderator
Posts: 654
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by WhiteWolf »

josteph wrote: June 22nd, 2019, 8:41 am @WhiteWolf If you have a savefile that reproduces this, feel free to upload it, that might help someone figure it out.
See that's the thing - no matter how hard I try I can't reproduce it. I try reloading the same save, try to move my units exactly as I did - the AI probably won't though - and nothing. It works just fine. I'm dumbstruck - I can't see what can possibly go wrong here, and I am failing to reproduce it...
Here it is though.
TRS-The Inn (6)-Auto-Save2.gz
The error happened after the AI's turn end with player 1's turn refresh at the start of turn 3.
(317.32 KiB) Downloaded 112 times
Ravana wrote: June 21st, 2019, 11:36 pm Error message gives line 163, which just accesses unit location. Before that there is some logic about poisoned/slowed/petrified/unhealable status.
But what does it mean? What is an 'unknown unit' then? Did a location somehow pass the filter that had no unit on it? But that is plain impossible, based on the filter.
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
Ravana
Forum Moderator
Posts: 2457
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by Ravana »

Based on code I can only guess that one of those units was broken by adding status. Some lines before, in status block, same unit location was working.

Something like unit_placed event might be able to do it.
User avatar
josteph
Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by josteph »

Could extract_unit/put_unit pair in there have invalidated the variable somehow?
User avatar
WhiteWolf
Forum Moderator
Posts: 654
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by WhiteWolf »

Ravana wrote: June 22nd, 2019, 4:49 pm Based on code I can only guess that one of those units was broken by adding status. Some lines before, in status block, same unit location was working.

Something like unit_placed event might be able to do it.
Well, I tried manually adding different (even some custom) statuses to several units, couldn't reproduce the issue.
josteph wrote: June 22nd, 2019, 5:48 pm Could extract_unit/put_unit pair in there have invalidated the variable somehow?
I'm afraid I'm not familiar with the lua code behind the tag :hmm: So... I don't know.
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
Celtic_Minstrel
Developer
Posts: 1691
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by Celtic_Minstrel »

As for the precise meaning of the error, it means the Lua unit proxy did not refer to an actual unit. This situation is detectible by testing the u.valid key on the unit; it'll be nil in this situation, otherwise it'll return a string. Off the top of my head I'm not quite sure how the situation could come to pass... possibly if you called erase_unit at some point or if the unit died since the proxy was created or something? It might be possible that extract_unit would do it, as that function returns the extracted unit (with u.valid == "private"), so if you passed a unit as argument, that unit may become invalidated. That said, I'd consider it a bug if that happens.

The source of the error in the actual code would be here. Maybe that information can help someone else track down what's going on.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
WhiteWolf
Forum Moderator
Posts: 654
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by WhiteWolf »

(Sorry for the late answer, I did not notice this post until now).

I'm afraid I don't quite understand all of that, because I'm not familiar with how lua works. I only used the tag in OP.
All I can say is that since then, I could not reproduce the issue, not once, despite having played the same scenario many times. :(
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
Celtic_Minstrel
Developer
Posts: 1691
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [harm_unit] Lua error: bad argument #1 to '__index' (unkown unit)

Post by Celtic_Minstrel »

I guess it's probably a rare bug in the [harm_unit] tag's implementation, so it would need to be fixed there... which is something we need to worry about, not you. :)
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
Post Reply