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

Fixed display_text_formatted texts overwriting themself #243

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

MiranDMC
Copy link
Collaborator

@MiranDMC MiranDMC commented Dec 2, 2024

Apparently CTheScripts::NumberOfIntroTextLinesThisFrame is cleared on every script processing, not once peer render frame.
This caused GXT labels generated by multiple scripts to not be unique.

@MiranDMC MiranDMC requested a review from x87 December 2, 2024 16:31
gxt[6] += CTheScripts::NumberOfIntroTextLinesThisFrame; // unique label for each possible entry
char gxt[9] = { 0x01, 'C', 'L', 'E', 0x00, 0x00, 0x00, 0x00, 0x00 }; // enough space for even worst case scenario
_itoa(genericLabelCounter, gxt + 4, 36); // 0xFFFF -> "1ekf"
genericLabelCounter++;

textManager.AddFxt(gxt, text);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these keys ever removed from textManager, or we keep adding them?

Copy link
Collaborator Author

@MiranDMC MiranDMC Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are kept, but names are procedural and reused on each frame. So total sum of keys never exceeds max count of display_text_formatted calls in single draw frame.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, and why we convert the counter to text if previously we added it to the last byte?

in other words, why not:

gxt[6] += genericLabelCounter++;

Copy link
Collaborator Author

@MiranDMC MiranDMC Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericLabelCounter is cleared once peer render frame, so in theory multiple scripts can print total sum of more than 255 texts. Writing 2 byte number there is also no solution as 0x100 will result in string termination and 1 will be lost.
Base 36 'zzz' represents something around 46k of entries, so more than enough.

Copy link

@x87 x87 Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the game support that many draws? I thought the limit is 96

https://github.com/sannybuilder/docs/blob/en/scm-documentation/gta-limits.md

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fact draw texts buffer index is getting zeroed for every single script makes me start thinking the 96 limit might be peer script.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh? 96 * 96 = 9216 draws?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
32 scripts drawing 96 texts each.
Works, but as usually in case of GTA it is hard to tell if some array is not getting overflown.
Anyway, I'm not the one clearing drawn texts counter. Not sure if they copy text entries to some other array or actually just draw accumulated requests after processing of each script.

@MiranDMC MiranDMC merged commit dde625c into master Dec 4, 2024
1 check passed
@MiranDMC MiranDMC deleted the fix_draw_formatted branch December 4, 2024 01:02
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.

2 participants