OpenHantek / OpenHantek6022

OpenHantek6022 is a DSO software for Hantek USB digital signal oscilloscopes 6022BE / BL. Development OS is Debian Linux, but the program also works on FreeBSD, MacOS, RaspberryPi and Windows. No support for non-Linux related issues unless a volunteer steps in!
GNU General Public License v3.0
868 stars 153 forks source link

Crash (assert failure in stl operator[] '__glibcxx_requires_subscript') in GLScope::drawHistogramChannelGraph Histogram mode when switching between T-Y and X-Y view a few times #240

Closed ericfont closed 3 years ago

ericfont commented 3 years ago

Describe the bug Crash (assert failure in stl operator[] __glibcxx_requires_subscript) in GLScope::drawHistogramChannelGraph Histogram mode when switching between T-Y and X-Y view a few times.

To Reproduce Steps to reproduce the behavior:

  1. Using this config file which is basically just CH2 enabled at 2V scale and timebase 5 us and Samplerate 12 MS/s and calibration out of 100 kHz and HISTOGRAM Mode enabled: before-crash.conf.zip
  2. Select Horizontal format T-Y
  3. Select Horizontal format Y-X
  4. If doesn't crash yet, then keep switching between Y-X mode and T-Y mode until crash...crash always seems to happen on the switch from Y-X to T-Y and but doesn't happen when switching from T-Y to Y-X.
  5. Assert crash is raised with the following stack trace (screenshot from QtCreator): image

note that channel parameter is 1, however the graph.vaoHistogram array is empty. So it tries to access an array in memory which it shouldn't be allowed to.

Expected behavior Should be able to switch between X-Y and Y-X mode if the program allows me too. Either that or program should prohibit histogram mode or disable it when switching.

Screenshots If applicable, add screenshots or a video to help explain your problem.

Computer environment (please complete the following information):

Scope device (please complete the following information):

Additional context This bug happens on main branch from before my last PR, so my PR wasn't at fault.

ericfont commented 3 years ago

My initial theory is that upon switching, the Histogram isn't immediately created internally, and so then if a GLScope::paintEvent is triggered by the OS before the Histogram is created, then there is a risk that line 550 of glscope.cpp is called to drawHistogramChannelGraph, since the scope->histogram condition is true even though the vaoHistogram vector is empty.

ericfont commented 3 years ago

See https://github.com/OpenHantek/OpenHantek6022/pull/241 for a simple fix.