Skip to content

Commit

Permalink
Handle when Sprite render key not in SpriteAtlas
Browse files Browse the repository at this point in the history
* Resolves #1169
  • Loading branch information
ds5678 committed Feb 20, 2024
1 parent 669a55d commit 563e52e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/AssetRipper.Processing/Textures/SpriteProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static void ProcessSprite(ISprite sprite)
// Otherwise, if a SpriteAtlas reference is serialized into this sprite,
// we must recover the m_RD field of the sprite from the SpriteAtlas.
ISpriteAtlas? atlas = sprite.SpriteAtlasP;
if (atlas is not null && sprite.Has_SpriteAtlas())
if (atlas is not null)
{
if (sprite.Has_RenderDataKey() &&
atlas.RenderDataMap.TryGetValue(sprite.RenderDataKey, out ISpriteAtlasData? spriteData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ public static void GetSpriteCoordinatesInAtlas(this ISprite sprite, ISpriteAtlas
// if sprite doesn't belong to an atlas, consider its image as single sprite atlas

Vector2 cropBotLeft;
if (atlas is null || !sprite.Has_RenderDataKey())
if (atlas is not null && sprite.Has_RenderDataKey() && atlas.RenderDataMap.TryGetValue(sprite.RenderDataKey, out ISpriteAtlasData? atlasData))
{
sAtlasRect = sprite.RD.TextureRect.CastToStruct();
cropBotLeft = (Vector2)sprite.RD.TextureRectOffset;
sAtlasRect = atlasData.TextureRect.CastToStruct();
cropBotLeft = (Vector2)atlasData.TextureRectOffset;
}
else
{
ISpriteAtlasData atlasData = atlas.RenderDataMap[sprite.RenderDataKey];
sAtlasRect = atlasData.TextureRect.CastToStruct();
cropBotLeft = (Vector2)atlasData.TextureRectOffset;
sAtlasRect = sprite.RD.TextureRect.CastToStruct();
cropBotLeft = (Vector2)sprite.RD.TextureRectOffset;
}

Vector2 sizeDelta = sprite.Rect.Size() - sAtlasRect.Size();
Expand Down

0 comments on commit 563e52e

Please sign in to comment.