Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak with uastc #465

Closed
skaarj1989 opened this issue Aug 3, 2021 · 4 comments
Closed

Memory leak with uastc #465

skaarj1989 opened this issue Aug 3, 2021 · 4 comments

Comments

@skaarj1989
Copy link

skaarj1989 commented Aug 3, 2021

Lastest version (master)

Dumping objects ->
{55897} normal block at 0x0000010FFCBA4860, 24 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 
ktxTexture *tex;
ktxTexture_CreateFromMemory(
    buffer, length, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &tex);

if (ktxTexture_NeedsTranscoding(tex)) {
  result = ktxTexture2_TranscodeBasis(reinterpret_cast<ktxTexture2 *>(tex),
                                      KTX_TTF_RGBA32, 0);
}

// ... loading to gpu

ktxTexture_Destroy(tex);

https://drive.google.com/file/d/1Op0nDvdIfW6tJP5XVuSuHnZ3JvNenrza/view?usp=sharing

Image converted with toktx
--uastc 4 --uastc_rdo_l .5 --uastc_rdo_d 65536 --zcmp 22

--bcmp is ok, no leaks

@MarkCallow
Copy link
Collaborator

When is Dumping objects happening. If at program exit, how can you be sure the leak is in ktxTexture2_TranscodeBasis, as you seem to be indicating, and not in your load for loading to gpu? Can you narrow down the location of the leak?

@skaarj1989
Copy link
Author

skaarj1989 commented Aug 4, 2021

  1. Dumping objects happens at exit.
  2. Leaks occurs ONLY with --uastc compressed images.

Minimal repro:

#include <crtdbg.h>
#include "ktx.h"

int main(int, char *[]) {
#ifdef _DEBUG
  _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
#endif

  ktxTexture *tex;
  auto result = ktxTexture_CreateFromNamedFile(
    "D:/AO.ktx", KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &tex);

  ktxTexture_Destroy(tex);

  return 0;
}

https://drive.google.com/file/d/1Op0nDvdIfW6tJP5XVuSuHnZ3JvNenrza/view?usp=sharing

@skaarj1989 skaarj1989 changed the title Memory leak in ktxTexture2_TranscodeBasis with uastc Memory leak with uastc Aug 4, 2021
@MarkCallow
Copy link
Collaborator

Which version of the software are you using? On Mac the allocator diagnostics are showing any leaks with the latest version of the software.

The example in your most recent comment does not show a call to ktxTexture2_TranscodeBasis. Is that intentional?

The texture you posted has levelCount == 0 which tells the loader to generate mipmaps. Depending on the transcode target format and the OpenGL or Vulkan implementation you are using, this may not be possible and the upload will fail. In my case I'm transcoding to BC3. My Vulkan implementation can't generate mipmaps for that format. Somewhat to my surprise as BC3 is a block-compressed format, my OpenGL implementation can.

@skaarj1989
Copy link
Author

Which version of the software are you using?

master on Windows

The example in your most recent comment does not show a call to ktxTexture2_TranscodeBasis. Is that intentional?

Yes, it looks like ktxTexture2_TranscodeBasis is not to blame.

That code is actual minimal reproduction for the memory leak - just create and destroy.

MarkCallow added a commit that referenced this issue Aug 17, 2021
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 21, 2024
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 22, 2024
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 22, 2024
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 22, 2024
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants