Null free segfault before renderer is initialized

Open
#2,570 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
cpp, python

Research direction

Start with mvRawTexture::~mvRawTexture() in mvTextureItems.cpp and trace its unconditional FreeTexture(_texture) call into mvUtilities_linux.cpp, mvUtilities_win32.cpp, and mvUtilities_apple.mm. Run the minimal Python reproduction before viewport setup, then verify that deleting a raw texture before renderer initialization no longer segfaults and that cleanup remains safe when a texture was never created.

Written by the indexing model from the issue text.

Description

state: pending type: bug

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.so → FreeTexture → glDeleteTextures.

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.

Dominant language
C++
Stars
15.7k
Forks
790
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from hoffstadt/DearPyGui

All issues in hoffstadt/DearPyGui

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.