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

Renderer allocates 'zero sized' hunk chunks #55

Open
wtfbbqhax opened this issue Aug 4, 2022 · 1 comment
Open

Renderer allocates 'zero sized' hunk chunks #55

wtfbbqhax opened this issue Aug 4, 2022 · 1 comment

Comments

@wtfbbqhax
Copy link
Owner

GeneratePermanentShader allocates zero sized chunks via Hunk_Alloc. This may be benign but it probably is not.

First it updates state

        Hunk_SwapBanks();

The size of the allocated block will be different depending on HUNK_DEBUG

#ifdef HUNK_DEBUG
    size += sizeof(hunkblock_t);
#endif

    // round to cacheline
    size = (size+31)&~31;

With HUNK_DEBUG enabled size += 0 -> size = 64
Without size=0

It may cause a problem in release, or it may cause a problem in Debug builds which is not clear. Pointers are often tested on truthiness alone, rather than knowing the size of the allocation.

image

I added a counter to this and found it happens quite a lot, from startup loading ui main menu

p count_zero_sized_allocs
(int) $0 = 558
@wtfbbqhax
Copy link
Owner Author

Adding a early return null and the menu is still loaded, no issue, but it actually resulted in more memory allocation in most cases. The only values that decreased are "low tempHighwater", "high permanent" and "total hunks in use".

high tempHighwater is more than 2x the original

image

Interesting behavior

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

1 participant