diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index d211113e..9a367767 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -79,6 +79,7 @@ slug: /changelog ## master +* (2025.01.15) 修复`Chart`在运行时动态添加`Component`异常的问题 (#339) * (2025.01.08) 修复`TextMeshPro`关闭时残留组件影响`Text`初始化的问题 ## v3.13.0 diff --git a/Runtime/Internal/BaseChart.Component.cs b/Runtime/Internal/BaseChart.Component.cs index 32de3739..c4555cf2 100644 --- a/Runtime/Internal/BaseChart.Component.cs +++ b/Runtime/Internal/BaseChart.Component.cs @@ -52,6 +52,7 @@ namespace XCharts.Runtime public MainComponent AddChartComponent(Type type) { + InitListForFieldInfos(); if (!CanAddChartComponent(type)) { Debug.LogError("XCharts ERROR: CanAddChartComponent:" + type.Name); diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index df21b6f9..a1af1388 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -724,7 +724,7 @@ namespace XCharts.Runtime private void InitListForFieldInfos() { - if (m_TypeListForSerie.Count != 0) return; + if (m_TypeListForSerie.Count != 0 || m_TypeListForComponent.Count != 0) return; m_TypeListForComponent.Clear(); m_TypeListForSerie.Clear(); var fileds1 = GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);