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

Locked
User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

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

Post 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)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Build #103: Weapons breaking can throw exception

Post by Interkarma »

Thanks for the report. :)

R.D.
Posts: 379
Joined: Fri Oct 07, 2016 10:41 am

Re: Build #103: Weapons breaking can throw exception

Post 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.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Build #103: Weapons breaking can throw exception

Post 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.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Build #103: Weapons breaking can throw exception

Post 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.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

R.D.
Posts: 379
Joined: Fri Oct 07, 2016 10:41 am

Re: Build #103: Weapons breaking can throw exception

Post by R.D. »

Do you remember what type of weapon it was, if it was a bow or something else?

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Build #103: Weapons breaking can throw exception

Post 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?
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Jay_H
Posts: 4061
Joined: Tue Aug 25, 2015 1:54 am
Contact:

Re: Build #103: Weapons breaking can throw exception

Post 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.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Build #103: Weapons breaking can throw exception

Post 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.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

Locked