Hello Guest

[SOLVED] Problem with deleting textures and vbos

  • 4 Replies
  • 6506 Views
[SOLVED] Problem with deleting textures and vbos
« on: March 02, 2015, 22:00:32 »
Hello,
I'm currently working on an engine which has a resource manager which loads and unloads all textures, meshes, shaders automatically but sometimes if a mesh/texture is unloaded, but other meshes/textures also disappear. After letting the engine print out all texture and mesh id's which you get from glGenTextures/glGenBuffers, i noticed that some id's are the same (The output from println: http://pastebin.com/ib7uATmW).
In the file on pastebin is the id of the plane ibo and the id of the logo texture (which the engine deletes from the GPU after 10secs if its not used) the same and if the logo texture gets deleted with glDeleteBuffers, all plane meshes disappear (there are still some sphere meshes in the scene which stay there)
And I don't really know if I made a really stupid mistake or if there's something wrong with glGenTextures/glGenBuffers.

Edit:
The source code of the Mesh and the Texture class:
Mesh: http://pastebin.com/wjxVdu6v
Texture: http://pastebin.com/D6iCD1U3

I hope you can understand the problem and maybe know a solution to it and thanks in advance for helping me,
Katsu :D
« Last Edit: March 03, 2015, 13:19:16 by Katsu »

*

Offline abcdef

  • ****
  • 336
Re: Problem with deleting textures and vbos
« Reply #1 on: March 03, 2015, 06:21:26 »
for destroying textures glDeleteTextures is the way to go as the id reference counters are different to those that are used to generate buffers, this is why texture id's can be the same as the buffer id's (I get this too).

Can you post some code for where you delete things?

Re: Problem with deleting textures and vbos
« Reply #2 on: March 03, 2015, 12:48:01 »
I changed it to glDeleteTextures for deleting my textures while debugging (http://pastebin.com/D6iCD1U3 line 40). I just heard that you can also use glDeleteBuffers for textures which gives me the same result as if I would use glDeleteTextures. The planes which have the same id as the logo texture which I try to delete with glDeleteTextures disappear when I use glDeleteBuffers and also if I use glDeleteTextures.

Katsu

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Problem with deleting textures and vbos
« Reply #3 on: March 03, 2015, 13:10:09 »
Whenever you are confused about an OpenGL function, the docs are the way to go: https://www.opengl.org/sdk/docs/man3/

From glDeleteBuffers():
Quote
glDeleteBuffers silently ignores 0's and names that do not correspond to existing buffer objects.

From glDeleteTextures():
Quote
glDeleteTextures silently ignores 0's and names that do not correspond to existing textures.

glDeleteBuffers() will never affect any textures, but will delete buffers with the same id and glDeleteTextures() will never affect buffers but will delete textures with the same id.

Where did you get the idea that they were equivalent?

Re: Problem with deleting textures and vbos
« Reply #4 on: March 03, 2015, 13:18:59 »
I found the bug...
glDeleteBuffers(shaderID)  :(
To delete shaders it seems that you also need to use glDeleteProgram and then glDeleteShader for every shader.
I am sorry for having bothered you and thank you all for helping me find the error and learning something really important in OpenGL.. :D

Katsu
« Last Edit: March 03, 2015, 13:33:34 by Katsu »