Changeset 26774

Timestamp:
Apr 11, 2022, 6:28:41 PM (2 years ago)
Author:
Vladislav Belov
Message:

Avoids a crash if a texture size is not a power of two.

Tested By: Stan

Differential Revision: https://code.wildfiregames.com/D4586

Location:
ps/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/graphics/TextureConverter.cpp

    r25766 r26774  
    1 /* Copyright (C) 2021 Wildfire Games.
     1/* Copyright (C) 202 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    2020#include "TextureConverter.h"
    2121
     22
     23
    2224#include "lib/regex.h"
     25
    2326#include "lib/timer.h"
    24 #include "lib/allocators/shared_ptr.h"
    25 #include "lib/tex/tex.h"
    2627#include "maths/MD5.h"
    2728#include "ps/CLogger.h"
     
    348349    }
    349350
     351
     352
     353
     354
     355
     356
     357
    350358  �� // Check whether there's any alpha channel
    351359    bool hasAlpha = ((tex.m_Flags & TEX_ALPHA) != 0);
  • ps/trunk/source/graphics/TextureManager.cpp

    r26588 r26774  
    2323#include "graphics/TextureConverter.h"
    2424#include "lib/allocators/shared_ptr.h"
     25
    2526#include "lib/file/vfs/vfs_tree.h"
    2627#include "lib/hash.h"
     
    409410            texture->ResetBackendTexture(
    410411                nullptr, m_ErrorTexture.GetTexture()->GetBackendTexture());
     412
     413
     414
     415
     416
     417
     418
     419
     420
     421
     422
    411423            return;
    412424        }
     
    443455            texture->ResetBackendTexture(
    444456                nullptr, m_ErrorTexture.GetTexture()->GetBackendTexture());
     457
    445458            return;
    446459        }
     
    558571    void ConvertTexture(const CTexturePtr& texture)
    559572    {
    560         VfsPath sourcePath = texture->m_Properties.m_Path;
     573        VfsPath sourcePath = texture->m_Properties.m_Path;
    561574
    562575        PROFILE2("convert texture");
     
    566579        u32 version;
    567580        PrepareCacheKey(texture, hash, version);
    568         VfsPath looseCachePath = m_CacheLoader.LooseCachePath(sourcePath, hash, version);
    569 
    570 //      LOGWARNING("Converting texture \"%s\"", srcPath.c_str());
     581        const VfsPath looseCachePath = m_CacheLoader.LooseCachePath(sourcePath, hash, version);
    571582
    572583        CTextureConverter::Settings settings = GetConverterSettings(texture);
     
    855866    if (!IsLoaded())
    856867        return;
    857     else if (!m_TextureData)
     868    else if (!m_TextureData)
    858869    {
    859870        ResetBackendTexture(nullptr, m_TextureManager->GetErrorTexture()->GetBackendTexture());
  • ps/trunk/source/graphics/tests/test_TextureConverter.h

    r26122 r26774  
    1 /* Copyright (C) 2021 Wildfire Games.
     1/* Copyright (C) 202 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    8686        TS_ASSERT_EQUALS(texdata[8*4], texdata[16*4]);
    8787        TS_ASSERT_DIFFERS(texdata[16*4], texdata[24*4]);
     88
    8889
    89 //      for (size_t i = 0; i < tex.dataSize; ++i)
    90 //      {
    91 //          if (i % 4 == 0) printf("\n");
    92 //          printf("%02x ", texdata[i]);
    93 //      }
     90    void test_not_pot()
     91    {
     92        // CTextureConverter prints to logs in case of an error.
     93        TestLogger logger;
     94
     95        const VfsPath path = L"art/textures/b/npot.png";
     96
     97        CTextureConverter converter(m_VFS, false);
     98        CTextureConverter::Settings settings =
     99            converter.ComputeSettings(L"", std::vector<CTextureConverter::SettingsFile*>());
     100        TS_ASSERT(!converter.ConvertTexture(CTexturePtr(), path, L"cache/npot.png", settings));
     101        TS_ASSERT(logger.GetOutput().find("be power of two") != std::string::npos);
    94102    }
    95103};
  • ps/trunk/source/ps/Profiler2GPU.cpp

    r26760 r26774  
    287287#else // CONFIG2_GLES
    288288
     289
     290
     291
     292
     293
    289294CProfiler2GPU::CProfiler2GPU(CProfiler2& profiler) :
    290295    m_Profiler(profiler)
Note: See TracChangeset for help on using the changeset viewer.