我收到了一份错误报告,似乎来自以下代码:
public class AnimationChannelCollection : ReadOnlyCollection<BoneKeyFrameCollection>
{
private Dictionary<string, BoneKeyFrameCollection> dict =
new Dictionary<string, BoneKeyFrameCollection>();
private ReadOnlyCollection<string> affectedBones;
// This immutable data structure should not be created by the library user
internal AnimationChannelCollection(IList<BoneKeyFrameCollection> channels)
: base(channels)
{
// Find the affected bones
List<string> affected = new List<string>();
foreach (BoneKeyFrameCollection frames in channels)
{
dict.Add(frames.BoneName, frames);
affected.Add(frames.BoneName);
}
affectedBones = new ReadOnlyCollection<string>(affected);
}
public BoneKeyFrameCollection this[string boneName]
{
get { return dict[boneName]; }
}
}
这是读取字典的调用代码:
public override Matrix GetCurrentBoneTransform(BonePose pose)
{
BoneKeyFrameCollection channel = base.AnimationInfo.AnimationChannels[pose.Name];
}
这是创建字典的代码,发生在启动时:
// Reads in processed animation info written in the pipeline
internal sealed class AnimationReader : ContentTypeReader<AnimationInfoCollection>
{
/// <summary>
/// Reads in an XNB stream and converts it to a ModelInfo object
/// </summary>
/// <param name="input">The stream from which the data will be read</param>
/// <param name="existingInstance">Not used</param>
/// <returns>The unserialized ModelAnimationCollection object</returns>
protected override AnimationInfoCollection Read(ContentReader input, AnimationInfoCollection existingInstance)
{
AnimationInfoCollection dict = new AnimationInfoCollection();
int numAnimations = input.ReadInt32();
/* abbreviated */
AnimationInfo anim = new AnimationInfo(animationName, new AnimationChannelCollection(animList));
}
}
错误信息如下:
我本应该得到一个带有错误键的KeyNotFoundException,但是却收到了“索引超出了数组范围”的异常。我不明白这个代码中如何会出现这种异常?索引超出了数组范围。
行:0
位置:System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
位置:System.Collections.Generic.Dictionary`2.get_Item(TKey key)
位置:Xclna.Xna.Animation.InterpolationController.GetCurrentBoneTransform(BonePose pose)
另外,这段代码是单线程运行的。
return dict[boneName];
。 - David LKeyNotFoundException
。你需要更新你的代码以正确重现该问题,因为目前它不能。 - David L