From 296cf038b91e79582f6f7940b5dd95361b31c8cf Mon Sep 17 00:00:00 2001 From: Hongxu Xu Date: Thu, 12 Nov 2020 01:40:39 +0800 Subject: [PATCH] Lock m_renderMain in Grapher::TryInitializeGraph to avoid modifying m_graph during rendering (#1430) --- src/GraphControl/Control/Grapher.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/GraphControl/Control/Grapher.cpp b/src/GraphControl/Control/Grapher.cpp index 1132eda..4caa25e 100644 --- a/src/GraphControl/Control/Grapher.cpp +++ b/src/GraphControl/Control/Grapher.cpp @@ -118,7 +118,7 @@ namespace GraphControl { if (m_graph != nullptr && m_renderMain != nullptr) { - if(auto renderer = m_graph->GetRenderer()) + if (auto renderer = m_graph->GetRenderer()) { HRESULT hr; @@ -281,7 +281,7 @@ namespace GraphControl void Grapher::PlotGraph(bool keepCurrentView) { - TryPlotGraph(keepCurrentView,false); + TryPlotGraph(keepCurrentView, false); } task Grapher::TryPlotGraph(bool keepCurrentView, bool shouldRetry) @@ -587,7 +587,7 @@ namespace GraphControl auto lineColor = eq->LineColor; graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A); - if (eq->GraphedEquation) + if (eq->GraphedEquation) { if (!eq->HasGraphError && eq->IsSelected) { @@ -1085,7 +1085,6 @@ void Grapher::OnGraphBackgroundPropertyChanged(Windows::UI::Color /*oldValue*/, } } - void Grapher::OnGridLinesColorPropertyChanged(Windows::UI::Color /*oldValue*/, Windows::UI::Color newValue) { if (m_renderMain != nullptr && m_graph != nullptr) @@ -1106,13 +1105,14 @@ void Grapher::OnLineWidthPropertyChanged(double oldValue, double newValue) m_renderMain->SetPointRadius(LineWidth + 1); m_renderMain->RunRenderPass(); - TraceLogger::GetInstance()->LogLineWidthChanged(); + TraceLogger::GetInstance()->LogLineWidthChanged(); } } } optional>> Grapher::TryInitializeGraph(bool keepCurrentView, const IExpression* graphingExp) { + critical_section::scoped_lock lock(m_renderMain->GetCriticalSection()); if (keepCurrentView || IsKeepCurrentView) { auto renderer = m_graph->GetRenderer();