# How to solve the Line plot error?

**URL:** https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691
**Category:** Support
**Created:** [November 20, 2020, 7:10am UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691 "2020-11-20T07:10:40Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![nia38](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/7ba0ec/32.png) [@nia38](https://discourse.vtk.org/u/nia38)
#### Post date: [November 20, 2020, 7:10am UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691/1 "2020-11-20T07:10:40Z")

</div>

I’m referring to an example of a line plot, and if the button is pressed with MFC, it’s printed on picture control.

It works normally when the button is pressed for the first time, but if you plot it again, an error will appear. How should I handle this?

my code is here:

vtkNew table;

```
vtkNew<vtkFloatArray> arrX;
arrX->SetName("X Axis");
table->AddColumn(arrX);

vtkNew<vtkFloatArray> arrC;
arrC->SetName("Line Profile");
table->AddColumn(arrC);

// Fill in the table with some example values
int numPoints = 550;
float inc = 1;//7.5 / (numPoints - 1);
table->SetNumberOfRows(numPoints);
for (int i = 0; i < numPoints; ++i)
{
	table->SetValue(i, 0, i * inc);
	table->SetValue(i, 1, meanMat[i]);//cos(i * inc));
}

// Set up the view
vtkNew<vtkContextView> view;
view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);

// 추가
view->SetRenderWindow(m_vtkRenderWindow);

// Add multiple line plots, setting the colors etc
vtkNew<vtkChartXY> chart;
view->GetScene()->AddItem(chart);
vtkPlot *line = chart->AddPlot(vtkChart::LINE);
line->SetInputData(table, 0, 1);
line->SetColor(255, 0, 0, 255);
line->SetWidth(3.0);

// For dotted line, the line type can be from 2 to 5 for different dash/dot
// patterns (see enum in vtkPen containing DASH_LINE, value 2):

```

#ifndef WIN32  
line-\>GetPen()-\>SetLineType(vtkPen::DASH\_LINE);  
#endif  
// (ifdef-ed out on Windows because DASH\_LINE does not work on Windows  
// machines with built-in Intel HD graphics card…)

```
//view->GetRenderWindow()->SetMultiSamples(0);

// Start interactor
view->GetRenderWindow()->Render();
view->GetInteractor()->Initialize();

```

 ![screenshot](https://discourse.vtk.org/uploads/default/original/2X/2/29f0d9ce61c533b40f6ddf95fa0be662d83c0078.png)

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 21, 2020, 9:17pm UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691/2 "2020-11-21T21:17:22Z")

</div>

Hello,

Can you post the error message?

regards,

Paulo

---

<div class="post-metadata">

### Author: ![nia38](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/7ba0ec/32.png) [@nia38](https://discourse.vtk.org/u/nia38)
#### Post date: [November 22, 2020, 11:44pm UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691/3 "2020-11-22T23:44:40Z")

</div>

Hello, Paulo.

Thank you, reply the message.

My error message is that…

Unhandled exception in “…exe”: 0x00007FFD650A6259(vtkViewsContext2D-8.90d.dll) Access violation reading location 0xC0000005: 0xFFFFFFFFFFFFFFFF.

i don’t know why the displaying the message. I just hope that the redrawing a chart.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 23, 2020, 1:36pm UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691/4 "2020-11-23T13:36:29Z")

</div>

Hi,

Can you post the stack trace whan the crash ensues, please?

regards,

Paulo

---

<div class="post-metadata">

### Author: ![nia38](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/7ba0ec/32.png) [@nia38](https://discourse.vtk.org/u/nia38)
#### Post date: [November 24, 2020, 12:21am UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691/5 "2020-11-24T00:21:52Z")

</div>

Hi,

My program’s stack trace window is that

 ![screenshot](https://discourse.vtk.org/uploads/default/original/2X/9/9a3179a55460b71ce854975ac037d6bc097046e9.png)

Thank you, Paulo.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 26, 2020, 9:38pm UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691/6 "2020-11-26T21:38:19Z")

</div>

Triple check you are not mixing debug and non-debug libraries/binaries. Mixing them is not good and often leads the program to do seemingly unexplainable behavior or crashes (such as crashing after a return instruction).

---

<div class="post-metadata">

### Author: ![nia38](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/7ba0ec/32.png) [@nia38](https://discourse.vtk.org/u/nia38)
#### Post date: [November 27, 2020, 4:44am UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691/7 "2020-11-27T04:44:39Z")

</div>

Thank you, Paulo.

I found this problem.  
After initializing the chart, the render was resolved.

Thank you for spending a lot of time.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [November 27, 2020, 11:40am UTC](https://discourse.vtk.org/t/how-to-solve-the-line-plot-error/4691/8 "2020-11-27T11:40:58Z")

</div>

Hello,

Can you, please, post the code to initualize the chart so others with the same issue can apply your solution?

thanks,

Paulo
