Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting unused static textures leads to crash #1371

Closed
tsucres opened this issue Oct 25, 2021 · 2 comments
Closed

Deleting unused static textures leads to crash #1371

tsucres opened this issue Oct 25, 2021 · 2 comments
Labels
platform: Linux Linux specific issue priority: high high priority state: pending not addressed yet type: bug bug

Comments

@tsucres
Copy link

tsucres commented Oct 25, 2021

Version of Dear PyGui

Version: 1.0.2
Operating System: Ubuntu 20.04

My Issue/Question

I'd like to delete unused static textures. However, calling dpg.delete_item(texture_id) systematically crashes the app.

Maybe there is another, better, way of deleting textures I'm not aware of?

Or maybe they're supposed to be freed automatically when the reference count == 0? But in that case, I would expect them to disappear from the registry inspector.

To Reproduce

Run the code bellow and click on the button.

Expected behavior

I would expect

  1. the app not to crash,
  2. the old texture to be freed,
  3. the new image/texture to be shown in the window and
  4. a single texture being listed in the registry.

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

    dpg.create_context()
    dpg.create_viewport()
    dpg.setup_dearpygui()

    texture_tag = None
    img_item_id = None
    texture_registry_id = "__texture_registry" 
    
    def btn_callback(sender, appdata):
        global texture_tag

        # Maybe trying to delete a texture that is still used in the image item is not a good idea... so let's deleting it later...
        texture_to_delete_tag = texture_tag 
        
        s = np.random.randint(100, 200) # I want to load a completely different image, which might have a different size
        new_img = np.random.random([s, s, 4]).astype(np.float32)
        texture_tag = dpg.add_static_texture(s, s, new_img, parent=texture_registry_id)
        dpg.configure_item(img_item_id, texture_tag=texture_tag)
        if texture_to_delete_tag is not None: # Here the old texture shouldn't be used by anything, we should be able to delete it?
            # By commenting the following line, the program runs fine. But the textures seem to accumulate in the registry.
            dpg.delete_item(texture_to_delete_tag) # CRASH!
            
    with dpg.texture_registry(show=True, tag=texture_registry_id):
        texture_tag = dpg.add_static_texture(100, 100, np.random.random([100, 100, 4]).astype(np.float32), parent=texture_registry_id)
    with dpg.window(label="issue"):
        dpg.add_button(label="Press me", callback=btn_callback)
        img_item_id = dpg.add_image(texture_tag=texture_tag)

    dpg.show_viewport()
    dpg.start_dearpygui()
    dpg.destroy_context()
@tsucres tsucres added state: pending not addressed yet type: bug bug labels Oct 25, 2021
@hoffstadt hoffstadt added the priority: high high priority label Oct 25, 2021
@hoffstadt
Copy link
Owner

Hi, this doesn't seem to be happening on windows so I will have to check ubuntu tonight.

@bandit-masked
Copy link
Collaborator

This app demonstrates how to load and unload images textures.
https://github.com/IvanNazaruk/DearPyGui-ImageController

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Linux Linux specific issue priority: high high priority state: pending not addressed yet type: bug bug
3 participants