hoffstadt / hoffstadt/DearPyGui
Segmentation fault when plotting with x-values but no y-values
- Dominant language
- C++
- Stars
- 15.6k
- Forks
- 783
- PR merge metrics
- No merged PRs in 30d
Description
## Version of Dear PyGui
Version: 1.3.1
Operating System: Manjaro and Windows 10
- Tested on both a desktop and a laptop running Manjaro 21.2.1 (kernel 5.10.93-1-MANJARO)
- Tested also on the same laptop when running Windows 10 (21H1, build 19043.1466)
Python version: 3.10.1 (Manjaro) and 3.10.2 (Windows 10)
## My Issue/Question
Calling the e.g. the `add_line_series` or `add_scatter_series` functions with a non-empty list of x-values and an empty list of y-values causes a segmentation fault. It does not seem to matter if the argument is a list or a tuple. This issue may affect some other plotting functions.
## To Reproduce
Steps to reproduce the behavior in general:
1. Create a plot with an x-axis and at least one y-axis.
2. Call e.g. `add_line_series` or `add_scatter_series` with an empty list/tuple as the `y` argument.
Steps to reproduce the behavior with the provided example script:
1. Click on the right-most button (labeled `len(x) > 0, len(y) == 0`).
## Expected behavior
Nothing would be plotted (i.e. the same behavior as when an empty list/tuple is used as the `x` argument).
At least the `add_line_series` and `add_scatter_series` seem to handle various scenarios without crashing as can be seen when pressing any of the other buttons in the provided example.
## Standalone, minimal, complete and verifiable example
```python
#!/usr/bin/env python3
import dearpygui.dearpygui as dpg
from typing import List
def plot_data(x: List[int], y: List[int], axis: int):
dpg.delete_item(axis, children_only=True)
dpg.add_line_series(x, y, label="Line", parent=axis)
dpg.add_scatter_series(x, y, label="Scatter", parent=axis)
data: List[int] = [1, 2, 3, 4, 5]
dpg.create_context()
with dpg.window(width=-1, height=-1) as window:
with dpg.plot(label="Single", width=-1, height=-24) as plot:
dpg.add_plot_legend(outside=True, horizontal=True,
location=dpg.mvPlot_Location_North)
x_axis: int = dpg.add_plot_axis(dpg.mvXAxis, label="X")
y_axis: int = dpg.add_plot_axis(dpg.mvYAxis, label="Y1")
dpg.set_axis_limits(x_axis, min(data) - 1, max(data) + 1)
dpg.set_axis_limits(y_axis, min(data) - 1, max(data) + 1)
with dpg.group(horizontal=True):
dpg.add_button(label="len(x) == len(y)",
callback=lambda: plot_data(data, data, y_axis))
dpg.add_button(label="len(x) > len(y)",
callback=lambda: plot_data(data, data[:-1], y_axis))
dpg.add_button(label="len(x) < len(y)",
callback=lambda: plot_data(data[:-3], data, y_axis))
dpg.add_button(label="len(x) == 0, len(y) == 0",
callback=lambda: plot_data([], data, y_axis))
dpg.add_button(label="len(x) == 0, len(y) > 0",
callback=lambda: plot_data([], data, y_axis))
dpg.add_button(label="len(x) > 0, len(y) == 0",
callback=lambda: plot_data(data, [], y_axis))
dpg.create_viewport(title="Plotting segfault", width=800, height=600)
dpg.set_primary_window(window, True)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
```
Contributor guide
Assessment
This issue has not been assessed yet.