cimgui-go: Calling backend.DeleteTexture() crashes program

I’m making an app that shows a webcam preview in the GUI using GoCV (OpenCV). I need to delete the texture after I’m done drawing it to conserve GPU memory as every frame will be getting kept in VRAM. Calling backend.DeleteTexture() is crashing the entire program from within C function igDeleteTexture().

I can reproduce it with the following code example:

previewRgba, _ := imgui.LoadImage("test.jpeg")
previewTexture := backend.CreateTextureRgba(previewRgba, previewRgba.Bounds().Dx(), previewRgba.Bounds().Dy())

// imgui.Image(previewTexture, imgui.NewVec2(300, 300))

backend.DeleteTexture(previewTexture)

image image

Is there anything obvious that would be causing this? I am calling runtime.LockOSThread() and the crash is happening in goroutine 1 so I’m pretty sure glDeleteTextures() is getting called from the main thread as it should.

About this issue

  • Original URL
  • State: closed
  • Created 2 months ago
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@gucio321 Good call, re-wrote my code to treat the rendering as async, persisting the texture between frames and only deleting it when a new image is ready and I now have a stable camera feed with no memory leaks 😄

image

I suppose I know whats wrong.

Lets look at this

  glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
  glGenTextures(1, &texId);
  glBindTexture(GL_TEXTURE_2D, texId);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR

  // Restore state
  glBindTexture(GL_TEXTURE_2D, last_texture);

^this is from Create Texture so this reffers to last texture, but we have no last texture because we bind 0 to it (or if we removed binding call in delete texture call there is something strange there. Null?)

we should deffinitly proceed this in DeleteTexture somehow

@tenten8401 now it works for me