X Tutup
Skip to content

Fix Atlas Merge Tool crash#101407

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
nattyrice:atlas-merge-tool-fix
Nov 25, 2025
Merged

Fix Atlas Merge Tool crash#101407
Repiteo merged 1 commit intogodotengine:masterfrom
nattyrice:atlas-merge-tool-fix

Conversation

@nattyrice
Copy link
Contributor

Fixes #101132
The fix exposed broken merging logic of atlases with animations.
Merging now properly copies animation frame locations
as well as correct sizing from input atlases to the merged atlas.

@nattyrice
Copy link
Contributor Author

Any chance this fix could be backported to 4.3?

@AThousandShips AThousandShips changed the title Fixes Atlas Merge Tool Crash Fix Atlas Merge Tool Crash Jan 11, 2025
Copy link
Member

@groud groud left a comment

Choose a reason for hiding this comment

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

Thanks! Aside from my small comment it looks good.

Vector2i separation = atlas_source->get_tile_animation_separation(tile_id);
// Because `separation` is just the space between,
// the vector is off by 1 in one(or both) component(s).
separation.x += (separation.x) ? 1 : 0;
Copy link
Member

Choose a reason for hiding this comment

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

Those two lines look a bit weird to me. I think the rationale is kind ok but I don't understand why there's a check on whether or not separation.x or separation.y are 0. Wouldn't be seperation += Vector2i(1,1) be enough?

Copy link
Contributor Author

@nattyrice nattyrice Jan 13, 2025

Choose a reason for hiding this comment

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

We only need to add 1 to the animation frame movements that are intended. For example, if there is 0 separation for the y component then we aren't selecting any frames to the left and right at all, so adding 1 to it would alter that behavior and not be what we want.

As I was writing the above I realize I hadn't checked the 0 separation case's result in the editor, and I should probably have done that. Sure enough, it fails. I haven't been reasoning about this properly. I am leaving my crossed out comment there to hopefully explain my original train of thought. I should have remembered to test the normal cases as well.

The use of x, y, and combined with column count isn't my normal mental model for animation sequences. However, always adding (1,1) to separation doesn't quite work either. It results in the destination position moving in a diagonal - which does match my original intuitions.

I am working out how to take the src_rect's position, adjusting it to be tile coords and then multiplying it to align with the new atlas size.

Something like this:

	Rect2i src_rect = atlas_source->get_tile_texture_region(tile_id, frame);
	Size2i src_size = src_rect.get_size();				
	Vector2i new_position = Vector2i(
		src_rect.position.x / src_size.width * new_texture_region_size.width,
		src_rect.position.y / src_size.height * new_texture_region_size.height
	);

But that isn't quite working right yet either - though I think I am on the right trail. It leaves worrying about the frame(and separation) to the get_tile_texture_region() call.

If it weren't for the fact that the two merging atlases could use different sized tiles it would be a simple 1 to 1 copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not on the right trail with my last comment. This time I took heavy inspiration from get_tile_texture_region() and realized a few areas where I was mistaken before.

With that said, unfortunately I just found a new issue in my last round of checks where it fails to properly merge 4 of my larger tilesets. I will have to look deeper into it tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just found a new issue in my last round of checks where it fails to properly merge 4 of my larger tilesets.

This issue has now been fixed. It wasn't properly enlarging the merged atlas vertical size when a tileset had vertical animation sequences. This has now been addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@groud You were right that the the conditional addition to separation was weird. I was nearly completely off with how I understood things to work. Thank you for catching that. I believe I have the right solution now.

The addition of (1,1) could now be thought of as being handled by the size_in_atlas variable in this line

@nattyrice nattyrice requested a review from groud January 14, 2025 11:11
@nattyrice
Copy link
Contributor Author

Thanks! Aside from my small comment it looks good.

I've made the changes requested(as much as they apply after several realizations) and marked it as resolved from my end. Is there anything else I need to do?

@Repiteo Repiteo modified the milestones: 4.4, 4.5 Feb 24, 2025
@Repiteo Repiteo modified the milestones: 4.5, 4.6 Sep 8, 2025
@Repiteo
Copy link
Contributor

Repiteo commented Nov 18, 2025

Could you rebase your PR & squash your commits? See our pull request guidelines for more information

@nattyrice nattyrice requested a review from a team November 19, 2025 20:59
@nattyrice
Copy link
Contributor Author

Could you rebase your PR & squash your commits? See our pull request guidelines for more information

My experience with git is quite limited. I am using github desktop. It was giving me a bunch of guff but I think I managed to get it to cooperate in the end.

I've been waiting so long for someone to reach back on this I've completely brain dumped everything regarding it.

@AThousandShips
Copy link
Member

The branch is still not squashed, you probably didn't force push your branch at the end with git push --force

@nattyrice nattyrice force-pushed the atlas-merge-tool-fix branch from fcec71d to 53b5b47 Compare November 21, 2025 00:26
@nattyrice
Copy link
Contributor Author

The branch is still not squashed, you probably didn't force push your branch at the end with git push --force

That seems to have done it. Thank you!

Copy link
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

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

Great job! All that you need to do now is change the commit message to the GitHub title, as we want to avoid directly listing issue/PR links in them (they'll cause unwanted messages otherwise)

@AThousandShips

This comment was marked as resolved.

@nattyrice nattyrice force-pushed the atlas-merge-tool-fix branch from c021225 to 264d35d Compare November 21, 2025 19:06
@AThousandShips

This comment was marked as resolved.

@nattyrice nattyrice force-pushed the atlas-merge-tool-fix branch from 264d35d to 2cbdffe Compare November 21, 2025 19:09
@AThousandShips
Copy link
Member

@groud do you still have reservations about this? Can you approve otherwise?

@akien-mga akien-mga added cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release labels Nov 25, 2025
@Repiteo Repiteo merged commit 22a28e0 into godotengine:master Nov 25, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 25, 2025

Thanks! Congratulations on your first merged contribution! 🎉

@nattyrice
Copy link
Contributor Author

Congratulations on your first merged contribution! 🎉

Thanks! I appreciate all the help through my fumbling with this.

@akien-mga akien-mga changed the title Fix Atlas Merge Tool Crash Fix Atlas Merge Tool crash Nov 27, 2025
@akien-mga
Copy link
Member

Cherry-picked for 4.5.2.

@akien-mga akien-mga removed cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release labels Jan 15, 2026
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.

Atlas Merge Tool crashes when selecting entries to merge 2

5 participants

X Tutup