ngscopeclient / scopehal

Test and measurement hardware abstraction library and protocol decodes. This is the library only. Most users should use scopehal-apps.
BSD 3-Clause "New" or "Revised" License
216 stars 97 forks source link

Changing units causes histogram to either not display data or to crash #881

Closed mx-shift closed 2 months ago

mx-shift commented 9 months ago

Built at 58af58e on Fedora 39. nVidia Quadro P600 with nVidia 545.29.06 drivers.

If I import 00.0.revolution1.500_flashfloppy_v341.csv, I get a waveform display with the Y units default to volts. I can create a histogram and get data that appears to be correct.

The Y units are actually phase error measured in clock ticks so I tried to guess a more appropriate unit. Choosing either UI or dimensionless before creating a histogram, the waveform renders fine but the histogram is blank: image

If I change the Y units to UI or dimensionless after opening a histogram, I get a crash:

mxshift@eps-conduit .../build/src/ngscopeclient ❯ ./ngscopeclient
Floating point exception (core dumped)
mx-shift commented 9 months ago
Thread 8 "WaveformThread" received signal SIGFPE, Arithmetic exception.
[Switching to Thread 0x7fffc3e006c0 (LWP 13113)]
0x0000000000945500 in WaveformArea::RasterizeAnalogOrDigitalWaveform (this=0x13dcfc0,
    channel=std::shared_ptr<DisplayedChannel> (use count 3, weak count 0) = {...}, cmdbuf=..., clearPersistence=true)
    at /home/mxshift/Projects/thirdparty/github/ngscopeclient/scopehal-apps/src/ngscopeclient/WaveformArea.cpp:1768
1768        int64_t offset_samples = (offset - data->m_triggerPhase) / data->m_timescale;
Missing separate debuginfos, use: dnf debuginfo-install xorg-x11-drv-nvidia-libs-545.29.06-2.fc39.x86_64
(gdb) bt
#0  0x0000000000945500 in WaveformArea::RasterizeAnalogOrDigitalWaveform
    (this=0x13dcfc0, channel=std::shared_ptr<DisplayedChannel> (use count 3, weak count 0) = {...}, cmdbuf=..., clearPersistence=true) at /home/mxshift/Projects/thirdparty/github/ngscopeclient/scopehal-apps/src/ngscopeclient/WaveformArea.cpp:1768
ngscopeclient/scopehal-apps#1  0x00000000009465d9 in WaveformArea::RenderWaveformTextures
    (this=0x13dcfc0, cmdbuf=..., chans=std::vector of length 1, capacity 1 = {...}, clearPersistence=clearPersistence@entry=false) at /home/mxshift/Projects/thirdparty/github/ngscopeclient/scopehal-apps/src/ngscopeclient/WaveformArea.cpp:1709
ngscopeclient/scopehal-apps#2  0x000000000095d314 in WaveformGroup::RenderWaveformTextures
    (this=<optimized out>, cmdbuf=..., channels=std::vector of length 1, capacity 1 = {...}, clearPersistence=clearPersistence@entry=false) at /home/mxshift/Projects/thirdparty/github/ngscopeclient/scopehal-apps/src/ngscopeclient/WaveformGroup.cpp:166
ngscopeclient/scopehal-apps#3  0x000000000082b0c6 in MainWindow::RenderWaveformTextures
    (this=<optimized out>, cmdbuf=<optimized out>, channels=<optimized out>)
    at /home/mxshift/Projects/thirdparty/github/ngscopeclient/scopehal-apps/src/ngscopeclient/MainWindow.cpp:487
ngscopeclient/scopehal-apps#4  0x00000000008c6aec in Session::RenderWaveformTextures
    (this=<optimized out>, cmdbuf=<optimized out>, channels=<optimized out>)
    at /home/mxshift/Projects/thirdparty/github/ngscopeclient/scopehal-apps/src/ngscopeclient/Session.cpp:3429
ngscopeclient/scopehal-apps#5  0x0000000000969fd4 in RenderAllWaveforms
    (cmdbuf=..., session=0xfb2148, queue=std::shared_ptr<QueueHandle> (use count 3, weak count 0) = {...})
    at /home/mxshift/Projects/thirdparty/github/ngscopeclient/scopehal-apps/src/ngscopeclient/WaveformThread.cpp:167
ngscopeclient/scopehal-apps#6  0x000000000096a844 in WaveformThread (session=0xfb2148, shuttingDown=0xfb22f0)
    at /home/mxshift/Projects/thirdparty/github/ngscopeclient/scopehal-apps/src/ngscopeclient/WaveformThread.cpp:109
ngscopeclient/scopehal-apps#7  0x00007ffff4ee31e3 in std::execute_native_thread_routine (__p=0x38df6a0)
    at ../../../../../libstdc++-v3/src/c++11/thread.cc:104
ngscopeclient/scopehal-apps#8  0x00007ffff4bcb897 in start_thread (arg=<optimized out>) at pthread_create.c:444
ngscopeclient/scopehal-apps#9  0x00007ffff4c5280c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
(gdb)
azonenberg commented 9 months ago

This is suggestive of the histogram somehow ending up with X axis units of zero UI per pixel, leading to a divide-by-zero in the renderer.

Not immediately obvious how this is happening. Can you share the CSV?

mx-shift commented 9 months ago

It's linked in https://github.com/ngscopeclient/scopehal/issues/881

azonenberg commented 8 months ago

Hey I finally had some time to dig into this but the test file you uploaded is giving github cache errors and I can't download it. Not sure if it's just my local server or what but can you re-upload the test case?

azonenberg commented 2 months ago

Moved to scopehal as this is an issue (or series of issues) with the histogram filter.

azonenberg commented 2 months ago

The reason nothing is displayed is that it's trying to create a histogram with only one bin (and apparently rendering breaks in that edge case).

[HistogramFilter::Refresh] nmin = -24 UI, nmax = 2 UI
[HistogramFilter::Refresh] Calculated: 1 bins
[HistogramFilter::Refresh] Bin size: 28.6 UI
azonenberg commented 2 months ago

And it turns out the reason for this is that autoranging does not actually automatically calculate the bin size. You're asking for 100-UI wide bins by default so it's getting very confused.

Fix pending, will need to automatically choose a sane bin size if in autorange mode.