QCustomPlot Discussion and Comments

QCP 2.0 beta and OpenglReturn to overview


I am making an app that plots four plots in one window. This is how I am doing it:

1. promote a QOpenGLWidget to QCustomPlot.
2. declare #define QCUSTOMPLOT_USE_OPENGL
3. Check if OpenCL version is ok:

void OGLcheck()
	QGLWidget w;
	QGLFormat glFormat;
	glFormat.setVersion(2, 0);
	QGLWidget widget(glFormat);

	const QGLContext *context = widget.context();

	ogl_flag =   context->isValid() && (context->format().majorVersion() > 2);

4. turn on opengl in the plot if ogl_flag = true. using plot[channel]->setOpenGl(ogl_flag ).

5. after populating the plots with data point, i replot each of the four plot using a for loop.

Problem: there are two:
1. everytime i turn on all four plots, no matter in which order, the program throws a access violation error at mGlFrameBuffer->bind(); when the QCPPaintBufferGlFbo::clear(const QColor &color) is called. here is a call stack

QCPPaintBufferGlFbo::clear(const QColor & color) Line 908 C++
QCustomPlot::setupPaintBuffers() Line 14853 C++
QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) Line 14152 C++
randomPlot() Line 453 C++

2. everytime i resize the plot widget, no matter in which order, the program throws a access violation error. here is a call stack
QCPPaintBufferGlFbo::reallocateBuffer() Line 939 C++
QCPAbstractPaintBuffer::setSize(const QSize & size) Line 596 C++
QCustomPlot::setupPaintBuffers() Line 14852 C++
> QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) Line 14152 C++
QCustomPlot::resizeEvent(QResizeEvent * event) Line 14508 C++

any thoughts as to what is going on?

QCustomPlot isn't meant to be promoted from QOpenGLWidget, but from QWidget. Not sure that changes anything but just to be sure.

For clarification: You have four separate QCustomPlot instances all with opengl enabled, or do you have one instance with four axis rects?

I will go back to normal widgets to see if it makes a difference.

I have four plots four different QCustomPlot instances all with opengl activated. they are all in the same form, as a child to four different dock widget so that user may undock them to enlarge them individually.

i am out of ideas here :(

I tried promtpting from QWidget, but ran into same problem.

can you please confirm that a scenario such as this (four plots in one widow with opengl ) was part of testing during development. because if the problem is on my code, i will try to redo the code.

During development I tested with two QCustomPlot instances in one window with OpenGL and there are lines in place (context activating/deactivating, fbo binding/unbinding) that made that work, at least on my system. However I do believe that on other systems there might happen strange things that don't show up on mine. That's just the way hardware graphics acceleration works, it's always a bit of a hassle to have it running on a large set of hardware, driver and OS configuration.

To make sure it's not your code, please put two QCP instances in a fresh project and see if you can call customPlot->setOpenGl(true);on both of them without having issues. Also don't use the OGLCheck method that you posted above, because the QGLWidget that you're creating (and not releasing) might lock some graphics resources which then make QCP fail when accessing them.

Finding and hopefully resolving these kind of issues (at least on most common platforms) is the reason for the beta. It might be necessary to add code so the OpenGL context can be shared between QCustomPlot widget, looks like having multiple contexts and binding/unbinding when needed is something that doesn't work reliably.

Hi, thank you for the reply. I donot mind codes not working properly, makes life interesting.

1. i turned off the checkOGL() and it still crashes.
2. having 2 opengl instances and two non-opengl instances combination donot have this problem.
3. i tried it on two machine, one with intel HD and one on nvidia quadro. both are version 4+. ill try in my home pc which has amd as well :p but i am not optimistic.
4. the problem is while changing the current context in "mGlContext.data()->makeCurrent(mGlContext.data()->surface())". the debug from QT complains "QOpenGLFramebufferObject::bind() called from incompatible context". i did not look into the QT source code, but from i reckon the context is incorrectly pointed or was destroyed by someother function

5. i added a few lines of debug code to the tool to see whats going off:

qDebug() << mGlContext.data()->isValid(); //out= true
  qDebug() << mGlContext.data()->surface()->size();//cashes
  //mGlContext.data()->doneCurrent(); // no crash, but no image either
  if (!mGlContext.data()->makeCurrent(mGlContext.data()->surface())) //crashes
  {\\ does not print the output, suggesting the make Current function does not return anythin.
	  qDebug() << Q_FUNC_INFO << "Failed to make opengl context current";

6. i made sure that the thread from which this call was being made is the same as the gui thread that created the contexts, by asserting the thread id.

update: even if i use 2 plots, i get the qWarning "QOpenGLFramebufferObject::bind() called from incompatible context". but the program donot crash.

did you notice this during testing? thanks

Do people here have resolved this "bug" ?

I'm experiencing almost the same problem :

1) I promoted 2 QWidgets as a QCustomPlot (both are in the same window/dialog and have the OpenGL set with this function ->setOpenGl(true)

2) No errors come out when I initialize my plots

3) But when I drag one of my plot, and then hover on the other one, the second plot also get dragged with this warning : QOpenGLFramebufferObject::bind() called from incompatible context

So, do I have forgot to set some attributes and/or contexts since the only "special thing" I did with the plot was to set OpenGL to "true" !?

I would like to have two completely independants plots.

Qt Creator 4.2.1
Qt 5.7.1 MSVC_2015_64bits
QCustomPlot 2.0.0-beta