hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
13.22k stars 688 forks source link

crash when plot large data #1060

Open tiantian1645 opened 3 years ago

tiantian1645 commented 3 years ago

Version of Dear PyGui

Version: 0.8.26 Operating System: Windows 10

My Issue/Question

When plot large data the app will crash random. The example is more faster than my real project, but in my real project I plot two data evert 50 mS ,the app will random crach.

To Reproduce

Steps to reproduce the behavior:

  1. Just plot large data

Expected behavior

no crash

Screenshots/Video

Snipaste_2021-07-13_12-35-18

Standalone, minimal, complete and verifiable example

import time
from math import cos, pi
from threading import Thread

import dearpygui.dearpygui as dpg

plot_data = ([], [])

def test_callback(sender=None, data=None):
    print(f"test_callback sender {sender} data {data}")
    type = dpg.get_item_info(sender)["type"]
    print(f"{sender} {type} {data}")

with dpg.window(label="Tutorial", width=500, height=500) as window_id:
    cb = dpg.add_checkbox(label="Test", callback=test_callback)
    dpg.add_same_line()
    dpg.add_combo(items=[1, 2, 3, 4, 5], callback=test_callback)

    with dpg.plot(label="Plot", height=-1, callback=test_callback) as plot_id:
        x_axis = dpg.add_plot_axis(dpg.mvXAxis, label="")
        y_axis = dpg.add_plot_axis(dpg.mvYAxis, label="")
        real_plot_id = dpg.last_item()
        series_id = dpg.add_line_series(plot_data[0], plot_data[1], label="Test", parent=real_plot_id)

def mouse_move_handler(sender, app_data, user_data):
    mouse_pos = dpg.get_plot_mouse_pos()
    x_axis_limits = dpg.get_axis_limits(x_axis)
    y_axis_limits = dpg.get_axis_limits(y_axis)
    print(f"mouse_pos {mouse_pos} x_axis_limits {x_axis_limits} y_axis_limits {y_axis_limits} sender {sender} app_data {app_data} user_data {user_data}")

with dpg.handler_registry():
    dpg.add_mouse_wheel_handler(callback=mouse_move_handler)

def task():
    frame = 0
    while True:
        for _ in range(2000):
            dx = pi * frame / 180
            dy = cos(3 * pi * frame / 180)
            plot_data[0].append(dx)
            plot_data[1].append(dy)
            frame += 1
            # dpg.add_line_series(plot_data[0], plot_data[1], id=series_id, label="Test", parent=real_plot_id)
        try:
            dpg.set_value(series_id, (plot_data[0], plot_data[1]))
        except Exception as e:
            print(f"plot thread error {repr(e)}")
            break
        if frame % 10000 == 0:
            print(frame)
        if frame % 200000000 == 0:
            plot_data[0].clear()
            plot_data[1].clear()
            dpg.delete_item(real_plot_id, children_only=True)
            time.sleep(5)
        time.sleep(0.001)

t = Thread(target=task, daemon=True)
t.start()

dpg.show_debug()
dpg.start_dearpygui()
hoffstadt commented 3 years ago

I can't seem to get it to crash unless I let my computer run out of memory. Is there any chance this is what is happening on your machine?

tiantian1645 commented 3 years ago

No, sometime it will crash just after run a few second, and sometime it will run a long time. And in my real project when app crash , I check memory usage history and anything is normal. But when I zooms a plot with large data, the memory usage will increase sharply and cause crash.

https://user-images.githubusercontent.com/26370840/125550450-7e3eef5e-54e5-4e0c-9a6f-c82ee50f15c5.mp4

hoffstadt commented 3 years ago

I'm still looking into this.

MikaPaul commented 3 years ago

Maybe it's not relevant in this context ... But when I run the example code on my computer it crashs after resizing the main window (with title "Dear PyGui")

hoffstadt commented 2 years ago

Can we confirm if this is still an issue in 1.1?

rageSpin commented 1 year ago

On Windows 11, the standalone code crashes at the begin of the execution.:(. dearpygui version 1.8.0