Page 1 of 1

Build #103: Weapons breaking can throw exception [RESOLVED]

Posted: Sat Mar 24, 2018 7:39 pm
by Hazelnut
WHen a bow breaks and is auto-unequipped, FPSWeapon.Update() can throw an index out of range exception which prevents and further use of weapons. I assume this happens with other weapons, but only seen it with bows because they break so quickly. I had a quick look and don't feel I know enough about this code to fix it correctly. I think it depends on where the animation is since is a coroutine, so it doesn't always happen.

Code: Select all

IndexOutOfRangeException: Array index is out of range.
DaggerfallWorkshop.Game.FPSWeapon.UpdateWeapon () (at Assets/Scripts/Game/FPSWeapon.cs:239)
DaggerfallWorkshop.Game.FPSWeapon+<AnimateWeapon>c__Iterator0.MoveNext () (at Assets/Scripts/Game/FPSWeapon.cs:398)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

Re: Build #103: Weapons breaking can throw exception

Posted: Sat Mar 24, 2018 10:13 pm
by Interkarma
Thanks for the report. :)

Re: Build #103: Weapons breaking can throw exception

Posted: Sat Aug 25, 2018 2:06 pm
by R.D.
I can't reproduce this. I thought maybe it was somehow fixed by https://github.com/Interkarma/daggerfall-unity/pull/821, but even when reverting to the code before that PR was accepted, I can't get the exception to happen.

I modified the code slightly to make weapons break immediately on any attack, rather than testing with normal gameplay, but I don't think that would matter. I tried probably around 15 times in a row (counting both with the latest code and before the above PR) having my bow break, but no exceptions.

Re: Build #103: Weapons breaking can throw exception

Posted: Mon Sep 03, 2018 5:20 pm
by Hazelnut
I just tried this with latest codebase and the bow is now auto-unequipped when it breaks. This has successfully avoided the problem with animation I think. I should have mentioned that it was different frequencies on a Linux laptop with intel gfx and a windows pc with a 1050Ti. On the laptop it always happened, but on windows pc it was much rarer and difficult to repro. Thats why I was sure it was to do with the animation coroutine.

Re: Build #103: Weapons breaking can throw exception

Posted: Mon Oct 01, 2018 9:04 pm
by Hazelnut
I just had this happen - first time in ages. Bit different as it still occurred when weapon was auto-unequipped. Hand was mid animation and unusable as was any weapon I equipped.

Re: Build #103: Weapons breaking can throw exception

Posted: Sat Oct 20, 2018 2:08 pm
by R.D.
Do you remember what type of weapon it was, if it was a bow or something else?

Re: Build #103: Weapons breaking can throw exception

Posted: Sat Oct 20, 2018 6:21 pm
by Hazelnut
It's always a bow, mainly because they break so much faster than any other type of weapon, and also one of my test chars is an archer/linguist. I don't think it's specific to the weapon, and I think the randomness is due to a coroutine and animations being in progress when some other script is processing the breakage. It's quite rare now, I was staying away from investigating any more because this is not my code and it's quite involved. I might take another look since it's been around for so long now...

Should armour and non-bow weapons take more damage? I find that I need 2-3 bows to clear a dungeon with an archer, but never need to worry about armour or other weapons. Is that matching classic?

Re: Build #103: Weapons breaking can throw exception

Posted: Sat Oct 20, 2018 7:17 pm
by Jay_H
A melee weapon in classic should last several levels. The weakest (daggers) should go for a couple dungeons, and the longest-lasting (daikatanas and warhammers) should almost never wear down. Longevity also increases with weapon material.

Bows, however, do wear down very quickly in classic.

Re: Build #103: Weapons breaking can throw exception

Posted: Sat Oct 20, 2018 8:16 pm
by Hazelnut
I've taken another look at this, and it's definitely down to the animations being handled by a coroutine. What happens is when the bow breaks and is unequipped, the arrays the animation code is using are changed and because it's parallel code it then tries to index the array out of bounds.

I've added a try catch block to swallow the exception that occurs when the animation routine is in mid-flight when the arrays are changed. It logs a message into the output log and then can be used again seamlessly as far as the player is concerned. I don't think it's worth any more time on it, so will mark resolved unless anyone disagrees in the next day.