Skip to main content
gamedev.net
🔒 Locked

Freaky Weird Texture Problem

Started by zealouselixir May 29, 2002 at 11:27 PM 11 replies 1.1k views
Original Post
zealouselixir
zealouselixir
This is by far the weirdest OGL error I''ve ever had to deal with. Basically, when I try to load a texture, it winds up being overwritten - the texture ID of the newly loaded image is the same as a texture that was previously loaded and has not yet been removed from memory! I can hack-fix this by loading all the textures I need in the function they''re used in, ala
static bool Load = true;
if(Load)
{
    Load = false;
    Texture.Load("...");
} 
however, this method is ugly and inefficient, and I can''t just keep shifting stuff around. I first noticed this when my water texture was overwritten by a menu crosshair. I moved the water texture loading to the water drawing function using the method above, and it worked, but NOW, all my particles are being drawn as the crosshair! ARARRAHGHHGHGHHGHGGHGHHGGGGGGGGGGGG!!!! If anyone has had a problem like this, especially if you''ve found a solution, please help me out. Much appreciated. Peace, ZE. //email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[if you have a link proposal, email me.]
[twitter]warrenm[/twitter]
Maximus
Maximus
Perhaps you arent using glBindTexture to change the active texture ID.

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
zealouselixir
zealouselixir

#include "texture.h"

bool CTexture::Load(char* file_name)
{
unsigned char *BitmapData;

glGenTextures(1, &ID);

BitmapData = LoadBitmap(file_name, Height, Width);

if(!BitmapData)
MessageBox(0, "No BMP data!", file_name, MB_OK);

glBindTexture(GL_TEXTURE_2D, ID);

glTexImage2D(GL_TEXTURE_2D, 0, 3, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, BitmapData);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

if(BitmapData)
delete [] BitmapData;

/*char TexInfo[80];
strcpy(TexInfo, file_name);
strcat(TexInfo, " - ");
sprintf(TexInfo+strlen(TexInfo), "%i", ID);

Popup(TexInfo);*/

if(ID)
return true;
else
return false;
}

void CTexture::Use()
{
glBindTexture(GL_TEXTURE_2D, ID);
}

CTexture::~CTexture()
{
if(ID)
glDeleteTextures(GL_TEXTURE_2D, &ID);
}


So far, both posters have assumed my stupidity. This is not a 30-second error, so don''t suggest that I''ve left out some fundamental call that''ll magically fix my code. I''m telling you, the texture ID is getting assigned to a NEW TEXTURE UPON LOADING without the original texture being deleted.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]
[twitter]warrenm[/twitter]
zealouselixir
zealouselixir
Here's a log file.

data/models/ammobox/ammo.bmp - 1
data/fonts/trent.bmp - 2
data/level1/colormap.bmp - 3
data/particle/spark.bmp - 4
data/particle/spark_mask.bmp - 5
data/cut1/malygris.bmp - 6
data/cut1/zealous.bmp - 7
data/cut1/caffeine.bmp - 8
data/cut1/gamedev.bmp - 9
data/fonts/trent.bmp - 10
data/gui/main_menu.bmp - 1 // bad - ammo still in memory!
data/gui/cursor.bmp - 4 // bad - spark still in memory
data/level1/water.bmp - 6 // okay - malygris removed from memory
data/gui/gun2.bmp - 7 // okay - zealous removed from memory
data/gui/gun2mask.bmp - 8 // okay...
data/gui/hud.bmp - 9 // okay...
data/gui/hudmask.bmp - 10 // okay...
data/gui/crosshair.bmp - 11
data/gui/crosshairmask.bmp - 12
data/fonts/trent.bmp - 13


The question is - why are texture IDs being recycled when they still ought to be attached to a texture in memory?

[edited by - zealouselixir on May 30, 2002 1:15:57 PM]
[twitter]warrenm[/twitter]
yakuza
yakuza
It looks like you pass in a file name when you create each texture, but you reuse the ID.

Edit:
Ok, you posted the log after I posted above. Doing some more thinking..

[edited by - yakuza on May 30, 2002 1:14:29 PM]
----------------Amusing quote deleted at request of owner
gerogerber
gerogerber
Do you use multiple render contexts?

Gero
Mayrel
Mayrel
I had the same error when I made a texture class. In mine, the cause was my Context::setTexture function, which, to avoid unnessary GL calls, checked the Context::s_currentTexture variable to see if this texture was already the current texture.

This broke when I was doing text output - I used glPushAttributes (I think that's what it's called...) to save various bits of state, including GL's current texture name. When I popped the attributes off again, GL's texture changed back, but Context::s_currentTexture, which was set to the font texture, did not. Now when I draw text again, it thinks the font texture is already bound, so it doesn't bother changing it.

I solved my problem by maintaining my own state stack in parallel to GL's, so that my texture pointer and GL's texture name are always in synch.

Although this doesn't sound quite like the problem you're experiencing, perhaps something similar is going on.

Just a quick comment on your code - you should probably check to see if glGenTextures failed right after you call it, rather than right at the end.

Looks like that isn't the problem, then...



Just Plain Wrong



[edited by - Mayrel on May 30, 2002 1:20:45 PM]
zealouselixir
zealouselixir
gero: No.
yakuza: The ID is a member of the texture class.

Sorry if I sounded arrogant in my next-to-last post. It's quite likely that I'm at fault here. Thanks for the help so far.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]


[edited by - zealouselixir on May 30, 2002 1:39:00 PM]
[twitter]warrenm[/twitter]
JuNC
JuNC
quote:

glDeleteTextures(GL_TEXTURE_2D, &ID);



Just a thought, the prototype for this is:


void glDeleteTextures( sizei n, uint *textures );


Maybe it is killing more textures than you mean to (not sure what GL_TEXTURE_2D is defined to and I can''t be bothered to look right now).

Other than that, have you tried on other computers or using other drivers? possible crap drivers but I guess you must have tried OGL games and stuff which do this.
zealouselixir
zealouselixir
JuNC. Man, I can''t express my thanks to you...but THANK YOU! Fixed the problem just like *snap* that.

Thanks to everyone who gave this problem a shot, expecially Mayrel, who got me thinking about other issues.

Peace and thanks again,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]
[twitter]warrenm[/twitter]
mittens
mittens
quote:
Original post by ZealousElixir
Here''s a log file.

data/models/ammobox/ammo.bmp - 1
data/fonts/trent.bmp - 2
data/level1/colormap.bmp - 3
data/particle/spark.bmp - 4
data/particle/spark_mask.bmp - 5
data/cut1/malygris.bmp - 6
data/cut1/zealous.bmp - 7
data/cut1/caffeine.bmp - 8
data/cut1/gamedev.bmp - 9
data/fonts/trent.bmp - 10
data/gui/main_menu.bmp - 1 // bad - ammo still in memory!
data/gui/cursor.bmp - 4 // bad - spark still in memory
data/level1/water.bmp - 6 // okay - malygris removed from memory
data/gui/gun2.bmp - 7 // okay - zealous removed from memory
data/gui/gun2mask.bmp - 8 // okay...
data/gui/hud.bmp - 9 // okay...
data/gui/hudmask.bmp - 10 // okay...
data/gui/crosshair.bmp - 11
data/gui/crosshairmask.bmp - 12
data/fonts/trent.bmp - 13


The question is - why are texture IDs being recycled when they still ought to be attached to a texture in memory?

[edited by - zealouselixir on May 30, 2002 1:15:57 PM]


Now my question, why do you have a font named after me?


Trent (ShiningKnight)
THE Engine
trent@voxelsoft.com
zealouselixir
zealouselixir
Trent:

That might''ve been a joke, but it really is named after you. The font''s actual name is something like "OCR Extended Somethingsomething", but I thought back over my OpenGL experience and popped in the name that first came to mind

BTW, you NEVER get on AIM anymore. How''s life?

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]
[twitter]warrenm[/twitter]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.