Today I encountered access violation bug, that I can't fix by any means.
First of all - our program is using Qt plugin system. Part using Qwt is a plugin that will allow user to plot insides of dataset. And everything works fine and stable - unless we want to reload plugins. What it actually means - we just delete everything created by all plugins and create it from scratch again, just like it was the first time when program starts. So in this case my class using Qwt (inheriting QwtPlot) is destroyed, everything in it is destroyed, and then everything else somehow involved is destroyed. When we are done cleaning plot plugin is created again.
And algorithm causing this looks like that:
1. We start program, load dataset and plot one or more curves:
bug7.jpg
If we don't plot anything (no QwtPlotCurve was attached to plot) - bug will not appear. Plugin will be entirely destroyed, reloaded and it will work fine.
2. We reload plugin (destroy it entirely and make new identical one).
3. When we want to attach curve to the plot, so we can see it - write access violation appears.
We suppose that it may somehow involve Qwt itself (item attaching to be precise), because we are nearly sure that everything is deleted properly.
It looks like everything starts here:
QwtPlotWithFunctions is a class inheriting QwtPlot. In drawSignal we go past setSamples, so data given to curve is most probably (well, it always was) correct. When we reach attachment - this is for sure the place where everything starts to fall apart. We tested push_back marked by arrow and we are sure that program crashes on attachment. curves is a QVector containing pointers to QwtPlotCurves - they are created in memory when we load dataset, so there are as many curves as there are signals possible to plot.
Then debugger lead us further:
And it looks like everything ends up when qVariantSetValue is called. I uploaded only last 3 things debugger shows, because of limit of 4 images per post. I may upload the rest if you wish.
What may cause this kind of bug and where should we look for solution?
Bookmarks