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

Fix off-by-one error in TArray::prepare_to_handle #436

Merged

Conversation

dnchattan
Copy link
Contributor

@dnchattan dnchattan commented Mar 13, 2024

Description
Fixes #435 (forked from it's original issue). The new array size is incorrectly computed in TArray::prepare_to_handle and targets a size that is 1 less than the intended array size. This causes it to not zero out and resize except for when you add additional elements after it- this leaves a trail of zeroed out entries, with one "missing" because the size was off for each call.

Fixes # (issue) (if applicable)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Verified the following script reproduces the issue and outputs garbage for [4] and [5] the first time, and 0x0000 for [4] the second time ([5] still garbage). Updated code and tested script to confirm both iterations output 0x0000 for [4] and [5]. Additionally stepped through each iteration in the debugger to confirm the correct calls and values were being made.

print("TEST SCRIPT LOADED")

function printBaseId(ar, idx)
    local campId = ar[idx]
    print(string.format("BaseCampIds[%d] 0x%X%X%X%X", idx, campId.A, campId.B, campId.C, campId.D))
end

function printBases()
    PalGroupGuildBase = FindFirstOf("PalGroupGuildBase")
    if PalGroupGuildBase == nil then
        print("PalGroupGuildBase not found")
        return
    end
    print("-- dump BaseCampIds[1-5] --")
    for idx = 1, 5 do
        printBaseId(PalGroupGuildBase.BaseCampIds, idx)
    end
    print("-- repeat --")
    print("-- dump BaseCampIds[1-5] --")
    for idx = 1, 5 do
        printBaseId(PalGroupGuildBase.BaseCampIds, idx)
    end
    
end

RegisterKeyBind(Key.Z, printBases)

Checklist

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • I have added the necessary description of this PR to the changelog, and I have followed the same format as other entries.
  • Any dependent changes have been merged and published in downstream modules.

Screenshots (if appropriate)

Additional context

Add any other context about the pull request here.

assets/Changelog.md Outdated Show resolved Hide resolved
@Buckminsterfullerene02 Buckminsterfullerene02 merged commit f05e40d into UE4SS-RE:main Apr 3, 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

Successfully merging this pull request may close these issues.

[BUG - RELEASE] Lua - accessing new indexes in TArray does not correctly resize/zero memory
5 participants