View Full Version : glBindTexture() problem...
12-15-2003, 07:39 PM
I have a slight problem binding to a texture for mip-map generation. It causes my app to crahs every time. Here's the source.
typedef struct tagTEXDATA
unsigned int *Texture;
sTexData.numTextures = 0;
More = true;
Why is the bind code causing the app to crash? I'm lost on this one.
12-15-2003, 10:08 PM
Have you break from your while loop?
12-15-2003, 10:28 PM
you should try changing the following:
sTexData.numTextures = 0;
into something similar to:
for (int i=0; i<261; i++) glGentextures(i, sTexData.numTexture);
You won't have a chance to create 261 textures at once with id pointing to a pointer within a struct. Moreover you should also pay some attention at the way you are allocating the memory for the texture data (i.e. the *Texture pointer)
12-16-2003, 02:11 AM
CeccOman, that code would crash. The "numTextures" member isn't even the right variable type, let alone a pointer. On top of that, I never heard of glGenTextures() working like a 'realloc()' function, so if I call it on a previously allocated block of memory, it'll either crash or create a new location for memory while the old one now has no pointer and floats around, unable to be freed. There's a way to alocate more than 261 textures, I mean look at Unreal II or UT2003! Both have GL support and both load a ton of textures on certain maps, now I need to figure out how, IF that's my problem.
12-16-2003, 03:37 AM
glGenTextures fills a previously allocated block of unsigned ints with texture object names, that's all.
If you haven't allocated the memory which is pointed to by sTexData.Texture you should get a crash immediately when calling glGenTextures.
If not I guess you're "More" loop is exceeding the number of allocated textures.
Repeating what CeccOman also pointed out,
valid code could look like this:
sTexData.Texture = (unsigned int *) malloc(261 * sizeof(unsigned int));
if (sTexData.Texture != NULL)
sTexData.numTextures = 261;
for (i = 0; i < sTexData.numTextures; i++)
// do stuff
12-17-2003, 02:13 AM
You're right Sephiroth, my line doesn't make too much sense. Sorry for having mislead the solution to your problem.
12-17-2003, 06:01 AM
No prob Cecco, I imagine you just glanced at it for a sec and misundersttod part of it. No biggy.
Relic, I'd never allocated the pointer, but glGenTextures wasn't crashing, so that's probably it. I'll give it a shot after work and post the results.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.