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

GLES3: Fix glMapBufferRange return null when r_index + last_item_index > max_instance #81036

Conversation

jsjtxietian
Copy link
Contributor

@jsjtxietian jsjtxietian commented Aug 27, 2023

fixes #80986.
The origin code has bug because when r_index == data.max_instances_per_buffer, glMapBufferRange trys to map length = data.max_instances_per_buffer * sizeof(InstanceData) range from offset state.last_item_index * sizeof(InstanceData), but array buffer size is equal to data.max_instances_per_buffer * sizeof(InstanceData), smaller than length + offset, so the glMapBufferRange failed and returned null instead, and thus caused the crash.

r_index++;
if (r_index >= data.max_instances_per_buffer) {
...
void *buffer = glMapBufferRange(GL_ARRAY_BUFFER, state.last_item_index * sizeof(InstanceData), r_index * sizeof(InstanceData), GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
memcpy(buffer, state.instance_data_array, r_index * sizeof(InstanceData));

@jsjtxietian jsjtxietian requested a review from a team as a code owner August 27, 2023 10:09
@akien-mga akien-mga changed the title fix glMapBufferRange return null when r_index + last_item_index > max_instance GLES3: Fix glMapBufferRange return null when r_index + last_item_index > max_instance Aug 27, 2023
@akien-mga akien-mga added this to the 4.2 milestone Aug 27, 2023
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Good catch! Looks good to me

@clayjohn clayjohn added the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Aug 28, 2023
@akien-mga akien-mga merged commit 5491dcd into godotengine:master Aug 28, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@jsjtxietian jsjtxietian deleted the fix_RasterizerCanvasGLES3_add_to_batch_crash branch August 28, 2023 10:49
@YuriSizov YuriSizov removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Sep 21, 2023
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when TextureRect is visible and TileMap is scaled down
4 participants