Compiler bug?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
kazade
Insane DCEmu
Insane DCEmu
Posts: 145
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Tue May 02, 2017 3:11 pm
Has thanked: 3 times
Been thanked: 34 times

Compiler bug?

Post by kazade »

I just want to make sure I'm not being stupid:

Code: Select all

    if(tx1 != NULL && tx1->data == NULL) {
        fprintf(stderr, "No data for texture! (%p) %d\n", tx1, tx1->index);
    }
 
Is printing:

Code: Select all

No data for texture! (0x0) 0
How can it be not NULL, but print 0x0? This is while investigating weird corruption on textures that I can't understand :(

The full function is below:

Code: Select all

void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, TextureObject *tx1, GLubyte textureUnit) {
    if(!TEXTURES_ENABLED[textureUnit]) {
        context->txr2.enable = context->txr.enable = PVR_TEXTURE_DISABLE;
        return;
    }

    fprintf(stderr, "Texture Unit: %d Texture Ptr: %x\n", textureUnit, tx1);

    context->txr2.enable = PVR_TEXTURE_DISABLE;
    context->txr2.alpha = PVR_TXRALPHA_DISABLE;

    GLuint filter = PVR_FILTER_NEAREST;
    GLboolean enableMipmaps = GL_FALSE;

    switch(tx1->minFilter) {
        case GL_NEAREST_MIPMAP_LINEAR:
        case GL_NEAREST_MIPMAP_NEAREST:
        case GL_LINEAR_MIPMAP_LINEAR:
        case GL_LINEAR_MIPMAP_NEAREST:
            enableMipmaps = GL_TRUE;
        break;
    default:
        enableMipmaps = GL_FALSE;
    }

    if(enableMipmaps) {
        if(tx1->minFilter == GL_LINEAR_MIPMAP_NEAREST) {
            filter = PVR_FILTER_TRILINEAR1;
        } else if(tx1->minFilter == GL_LINEAR_MIPMAP_LINEAR) {
            filter = PVR_FILTER_TRILINEAR2;
        } else if(tx1->minFilter == GL_NEAREST_MIPMAP_LINEAR) {
            filter = PVR_FILTER_BILINEAR;
        } else {
            filter = PVR_FILTER_NEAREST;
        }
    } else {
        if(tx1->minFilter == GL_LINEAR && tx1->magFilter == GL_LINEAR) {
            filter = PVR_FILTER_BILINEAR;
        }
    }

    /* If we don't have complete mipmaps, and yet mipmapping was enabled, we disable texturing.
     * This is effectively what standard GL does (it renders a white texture)
     */
    if(!_glIsMipmapComplete(tx1) && enableMipmaps) {
        context->txr.enable = PVR_TEXTURE_DISABLE;
        return;
    }

    if(tx1 != NULL && tx1->data == NULL) {
        fprintf(stderr, "No data for texture! (%p) %d\n", tx1, tx1->index);
    }

    if(tx1 && tx1->data) {
        context->txr.enable = PVR_TEXTURE_ENABLE;
        context->txr.filter = filter;
        context->txr.mipmap = (enableMipmaps) ? PVR_MIPMAP_ENABLE : PVR_MIPMAP_DISABLE;
        context->txr.mipmap_bias = PVR_MIPBIAS_NORMAL;
        context->txr.width = tx1->width;
        context->txr.height = tx1->height;
        context->txr.base = tx1->data;
        context->txr.format = tx1->color;
        context->txr.env = tx1->env;
        context->txr.uv_flip = PVR_UVFLIP_NONE;
        context->txr.uv_clamp = tx1->uv_clamp;
        context->txr.alpha = PVR_TXRALPHA_ENABLE;
    } else {
        context->txr.enable = PVR_TEXTURE_DISABLE;
    }
}
kazade
Insane DCEmu
Insane DCEmu
Posts: 145
Joined: Tue May 02, 2017 3:11 pm
Has thanked: 3 times
Been thanked: 34 times

Re: Compiler bug?

Post by kazade »

OK, embarrassing...

Turns out that my texture memory allocation code was always calculating *zero* as the size required, so all texture uploads were trashing data.

Presumably this is just a side-effect of that :/
Post Reply