SomaZ / OpenJK

Community effort to maintain and improve Jedi Academy + Jedi Outcast released by Raven Software
GNU General Public License v2.0
11 stars 4 forks source link

Crash when loading hdr lightmaps #59

Closed AntiAnti closed 7 months ago

AntiAnti commented 8 months ago

It's quite weird. I get this crash when loading my baked lighting on laptop. It doesn't happen on desktop PC (why??) and doesn't happen on laptop with lighting baked by SomaZ (for t1_rail). The crash happens when it tries to load non-existing sky texture, but I didn't dig deeper. Anyway, solution is quite simple.

R_FindImageFile function in tr_image.cpp tries to load HDR image and then checks if it succeed by testing output buffer:

        R_LoadHDRImage(filename, &pic, &width, &height);
        if (pic == NULL)
            ...

The problem is, R_LoadHDRImage doesn't reset buffer to NULL if it failed. So, in shared/rd-rend2/tr_image_stb.cpp need to add three lines:

// Loads a HDR image from file.
void R_LoadHDRImage( const char *filename, byte **data, int *width, int *height )
{
    byte *buf = NULL;
    int x, y, n;

    int len = ri.FS_ReadFile (filename, (void **)&buf);
    if ( len <= 0 || buf == NULL )
    {
        // reset output varialbes
        *data = NULL;
        *width = 0;
        *height = 0;

        return;
    }
    ...
SomaZ commented 8 months ago

Meh, forgot to co-author you. Sorry about that. Hope that's ok.