[VSTGUI] How do I fix my custom view problem?

Hello.

I am making a simple FFT analyzer.
I don’t know if this is the right way, but through trial and error I have displayed the FFT analyzer in the following steps.

Steps:.
(1)process() to calculate FFT. (processor class)
(2) From the calculation results, std::vector<CDrawContext::LinePair> was created. (processor class)
(3)Send a message from the processor class to the controller class using the sendMessage() method. (processor class)
(4)Received the message and updated the std::vector<CDrawContext::LinePair> defined in its FFTView class. (controller class)
(5)addView(FFTView) was used to display the FFT analyzer. (The main GUIView class.)

The above worked well for the display of the analyzer. However, there is a high probability that the host crashes when inserting or deleting plug-ins in the track, and when saving the host’s project.
If I didn’t update the LineList in (4), the crash doesn’t happen, so I think this method is the cause, but I don’t know how to fix it.
As a clue, the crash dump generated by the host describes an access violation error.
Also, if I have only one of these plug-ins for a song project, no matter how many inserts or deletions I do, it won’t cause a crash.
The second and subsequent inserts will cause a high probability of crashing. (However, it will not crash on the second insert every time.)

part of the code
processor.cpp:

//in process() method
/*Calculated the FFT and then created std::vector<CDrawContext::LinePair> as linelist*/
Vst::IMessage* fftOut = Vst::ComponentBase::allocateMessage();
fftOut->setMessageID(u8"fftOut");
fftOut->getAttributes()->setBinary(u8"Out", (void*)&linelist, sizeof(std::vector<CDrawContext::LinePair>));
sendMessage(fftOut);

controller.cpp:

tresult PLUGIN_API Controller::notify(Vst::IMessage* message) {
	if (!message) { return kInvalidArgument; }
	if (!strcmp(message->getMessageID(), u8"fftOut")) {
		const void* dataOut;
		uint32 size;
		if (message->getAttributes()->getBinary(u8"Out", dataOut, size) == kResultOk) {
			if (view) {
				if (&view->getFFTView()) {
					view->getFFTView()->updateLineList(&view->getFFTView()->linelists, (std::vector<CDrawContext::LinePair>*)dataOut);
				}
			}
		}
		return kResultOk;
	}
	return EditControllerEx1::notify(message);
}

FFTView.cpp

FFTView::FFTView(const CRect& size) : CView(size) {
		timer = new CVSTGUITimer(this, fire_time, true);
	}

	FFTView::~FFTView() {
		if (timer) {
			timer->forget();
			timer = 0;
		}
	}

	void FFTView::draw(CDrawContext* pContext)
	{
		pContext->setDrawMode(kAntiAliasing);
		pContext->setFrameColor(kGreenCColor);
		pContext->setLineWidth(2);
		pContext->drawLines(linelists);
		setDirty(false);
	}
	
	CMessageResult FFTView::notify(CBaseObject* sender, IdStringPtr message) {
		if (message == CVSTGUITimer::kMsgTimer) {
			invalid();
			return kMessageNotified;
		}
		return kMessageUnknown;
	}
	
	void FFTView::updateLineList(std::vector<VSTGUI::CDrawContext::LinePair>* before, std::vector<VSTGUI::CDrawContext::LinePair>* after) {
		if (before && after) {
			*before = *after;
		}
	}

MainGUIView.cpp:

bool PLUGIN_API MainGUIView::open(void* parent, const PlatformType& platformType)
	{
		/*Abbreviated*/
		frame->open(parent);

		sav = new SpeAnaView(CRect(1, 0, 515, 150));
		frame->addView(sav);

		return true;
	}

void PLUGIN_API MainGUIView::close()
	{
		if (frame)
		{
			frame->forget();
			frame = 0;
		}
	}

FFTView* MainGUIView::getFFTView() {
		return fft_view; //field member
	}

VST SDK: 3.7.1
VSTGUI: 4.9
HOST: Studio One 5

Thank you!

this is my first time to post and I’m not used to English, so I’m afraid I’m not asking good questions…
By the way, the new site has a modern design and is very clear, isn’t it?

This problem was caused by my poor knowledge of computer memory.
Properly allocating and releasing memory in the constructor and destructor solved the problem!

FFTView.cpp

FFTView::FFTView(const CRect& size) : CView(size) {
		timer = new CVSTGUITimer(this, fire_time, true);
		linelists = (std::vector<CDrawContext::LinePair>*)malloc(sizeof(std::vector<CDrawContext::LinePair>));
	}

FFTView::~FFTView() {
		if (timer) {
			timer->forget();
		}
		free(linelists);
	}