DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

Null free segfault before renderer is initialized

Open spencerbug opened this issue 3 months ago • 0 comments

Version of Dear PyGui

Version: 1.11.1 (pip wheel), 2.1.0 Operating System: Ubuntu 24.04 (WSL2, Mesa llvmpipe)

My Issue/Question

Callling dpg.add_raw_texture before the viewport/renderer is initialized causes a hard crash when the texture item is destroyed. The raw texture’s destructor always calls FreeTexture, which forwards to glDeleteTextures. In this code path the OpenGL loader (gl3w) has not been initialized yet, so dlDeleteTextures is a null function pointer and the process segfaults. The crash happens even when the raw texture never created a GL texture (e.g. because we delete it immediately).

Relevant sources:

  • mvRawTexture::~mvRawTexture() in mvTextureItems.cpp (unconditionally calls FreeTexture(_texture))
  • FreeTexture implementations (mvUtilities_linux.cpp, mvUtilities_win32.cpp, mvUtilities_apple.mm) which unconditionally call the GL driver.

To Reproduce

  1. Start a fresh Python session with Dear PyGui 1.11.1.
  2. Run the minimal script below (note there is no viewport setup yet).
  3. Python terminates with SIGSEGV inside _dearpygui.soFreeTextureglDeleteTextures.

Expected behavior
Destroying a raw texture before the viewport/renderer is available should be a no-op, not a hard crash. Dear PyGui should either defer GL cleanup until the context exists or skip the glDeleteTextures call when _texture is null/uninitialized.

Screenshots/Video

Image

Standalone, minimal, complete and verifiable example

import numpy as np
import dearpygui.dearpygui as dpg

dpg.create_context()

with dpg.texture_registry():
    data = np.zeros((4,), dtype=np.float32)
    tex_id = dpg.add_raw_texture(1, 1, data)
    dpg.delete_item(tex_id)  # <- segfault inside FreeTexture/glDeleteTextures

print("unreachable")

But any solution that avoids calling into GL before the loader/context is ready would work. Let me know if you need additional traces or testing on other platforms.

spencerbug avatar Oct 28 '25 05:10 spencerbug