开发者

Why is this array selection causing such a glitchy phenomenon?

开发者 https://www.devze.com 2023-01-07 02:45 出处:网络
I was loading a image in openGl with the Glaux library when I came across a very strange phenomenon with a array. Some example of what I tried and if they succeeded or not are below. The curFreeId var

I was loading a image in openGl with the Glaux library when I came across a very strange phenomenon with a array. Some example of what I tried and if they succeeded or not are below. The curFreeId variable is global. The extra variables I created to test with are local to the function.

Since when does this effect the flow of code.

    unsigned int curFreeId = 0;
    modStruct->t[ i 开发者_StackOverflow].gluId = curFreeId;
    glGenTextures(1, &glTextureList[curFreeId]);
    glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);

vs

    modStruct->t[ i ].gluId = 0;
    glGenTextures(1, &glTextureList[0]);
    glBindTexture(GL_TEXTURE_2D, glTextureList[0]);

The first code will not work. The second will. Does anyone have any clue why this happens?

EDIT: Strangely enough, this also works correctly.

unsigned int curFreeId = 0;
modStruct->t[ i ].gluId = curFreeId;
glGenTextures(1, &glTextureList[0]);
glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);

and so does this.

unsigned int curFreeId = 0;
modStruct->t[ i ].gluId = curFreeId;
glGenTextures(1, &glTextureList[curFreeId]);
glBindTexture(GL_TEXTURE_2D, glTextureList[0]);

Continuing on with some testing. I came across even more curious results.

This works

    unsigned int curFreeId = 0;
    unsigned int curid = 0;
    modStruct->t[ i ].gluId = curFreeId;
    glGenTextures(1, &glTextureList[curid]);
    glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);

But this does not...

    unsigned int curFreeId = 0;
    unsigned int curid = curFreeId;
    modStruct->t[ i ].gluId = curFreeId;
    glGenTextures(1, &glTextureList[curid]);
    glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);

But this does...

    unsigned int curFreeId = 0;
    unsigned int curid = curFreeId = 0;
    modStruct->t[ i ].gluId = curFreeId;
    glGenTextures(1, &glTextureList[curid]);
    glBindTexture(GL_TEXTURE_2D, glTextureList[curFreeId]);

What is the world... Is this some glitch of some sort?


Okay... I just went through the entire project looking for all relations to curFreeId. I managed to find a random addition sign someplace.

curFreeId++;

I hate the simple bugs...

Thanks for your help guys. I managed to fix a few other bugs because of your suggestions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号