Skip to content

Commit

Permalink
better warning logs on invalid atlas xmls
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Jul 6, 2024
1 parent df5e0c2 commit 54d2d37
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
36 changes: 24 additions & 12 deletions flixel/graphics/frames/FlxAtlasFrames.hx
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,20 @@ class FlxAtlasFrames extends FlxFramesCollection
var frames:FlxAtlasFrames = FlxAtlasFrames.findFrame(graphic);
if (frames != null)
return frames;

if (graphic == null || xml == null)

final xmlData = xml.getFirstElement();
if (xmlData == null)
{
FlxG.log.warn('Invalid xml: $xml');
return null;

}

if (graphic == null)
return null;

frames = new FlxAtlasFrames(graphic);

var data:Access = new Access(xml.getXml().firstElement());
var data:Access = new Access(xmlData);

for (texture in data.nodes.SubTexture)
{
Expand Down Expand Up @@ -323,15 +330,20 @@ class FlxAtlasFrames extends FlxFramesCollection
var frames = FlxAtlasFrames.findFrame(graphic);
if (frames != null)
return frames;

if (graphic == null || xml == null)

final xmlData = xml.getFirstElement();
if (xmlData == null)
{
FlxG.log.warn('Invalid xml: $xml');
return null;

}

if (graphic == null)
return null;

frames = new FlxAtlasFrames(graphic);

final data = xml.getXml();

for (sprite in data.firstElement().elements())

for (sprite in xmlData.elements())
{
var trimmed = (sprite.exists("oX") || sprite.exists("oY"));
var rotated = (sprite.exists("r") && sprite.get("r") == "y");
Expand Down
5 changes: 5 additions & 0 deletions flixel/system/FlxAssets.hx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ abstract FlxXmlAsset(OneOfTwo<Xml, String>) from Xml from String
return cast(this, Xml);
}

inline public function getFirstElement()
{
return getXml().getFirstElement();
}

static inline function fromPath<T>(path:String):Xml
{
return fromXmlString(Assets.getText(path));
Expand Down

0 comments on commit 54d2d37

Please sign in to comment.