Opened 6 years ago

Last modified 3 years ago

#5022 new defect

Greyscale to RGBA texture conversion fails silently (failing Atlas heightmap import)

Reported by: elexis Owned by:
Priority: Should Have Milestone: Backlog
Component: Core engine Keywords:
Cc: Patch:

Description (last modified by elexis)

After importing an image as a heightmap to atlas, the vertex with the highest coordinates is wrong.

For example if you load an entirely black image, you get a flat surface with one pixel at the corner up in the sky.

https://trac.wildfiregames.com/raw-attachment/ticket/5022/example2.jpg (See #5021 for the wrong border, this ticket is only about that one corner)

Attachments (1)

example2.jpg (89.7 KB ) - added by elexis 6 years ago.

Download all attachments as: .zip

Change History (9)

by elexis, 6 years ago

Attachment: example2.jpg added

comment:1 by elexis, 6 years ago

Description: modified (diff)

comment:2 by elexis, 6 years ago

Component: Atlas editorCore engine
Milestone: Alpha 23Backlog
Owner: elexis removed
Status: assignednew
Summary: Atlas heightmap image off by 1 byte wrong texture decodingGreyscale to RGBA texture conversion fails silently (failing Atlas heightmap import)

When loading a greyscale png, the code of r12308 first tries to convert it to RGBA. But that silently fails. tex.m_Flags consists of only TEX_GREY and TEX_TOP_DOWN after the tex.transform_to. Then the following heightmap import code still reads 3 channels per pixel, which results in an out of bounds read for the very last pixel.

So it's something wrong with the texture conversion code, not with the atlas heightmap import code apparently.

comment:3 by Stan, 6 years ago

Does that code handle the other texture loading because I know some of our AO and spec textures use grayscale to save size.

comment:4 by elexis, 6 years ago

yes

comment:5 by elexis, 3 years ago

Workaround in r25843, duplicate at #6261

comment:6 by Vladislav Belov, 3 years ago

The bug is inside tex.cpp, the code fails to an add alpha channel to a grayscale image. Even in case it's going to be converted to a color image:

if(transforms & TEX_ALPHA)
{
    // add alpha channel
    if(bpp == 24)
    {
        dstSize = (srcSize / 3) * 4;
        t->m_Bpp = 32;
    }
    // remove alpha channel
    else if(bpp == 32)
    {
        return INFO::TEX_CODEC_CANNOT_HANDLE;
    }
    // can't have alpha with grayscale
    else
    {
        return INFO::TEX_CODEC_CANNOT_HANDLE;
    }
}

comment:7 by wraitii, 3 years ago

(would argue it's not necessarily a bug, but would probably be nice to implement. That said, the ticket is named incorrectly, as the failure is very much not silent.)

in reply to:  7 comment:8 by Vladislav Belov, 3 years ago

Replying to wraitii:

(would argue it's not necessarily a bug, but would probably be nice to implement. That said, the ticket is named incorrectly, as the failure is very much not silent.)

Nope, it fails silently. So it's the bug.

Note: See TracTickets for help on using tickets.