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

fix: Bug in loading SVG though a spritesheet #10604

Closed
wants to merge 8 commits into from

Conversation

AnkushSarkar10
Copy link

Description of change

Fixed a bug where asset.data was undefined when loading a spritesheet which links to an svg as such

(spritessheet.json)

{
  "frames": {
    "default": {
         ...
    }
  },
  "meta": {
    "app": "...",
    "version": "...",
    "image": "someSvg.svg",
    "format": "..."
  }
}
Pre-Merge Checklist
  • Lint process passed (npm run lint)
  • Tests passed (npm run test)

Copy link

codesandbox-ci bot commented Jun 4, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6b41d1e:

Sandbox Source
pixi.js-sandbox Configuration

@AnkushSarkar10 AnkushSarkar10 changed the title Fix: Loading SVG though a spritesheet fix: Bug in loading SVG though a spritesheet Jun 4, 2024
Copy link
Member

@bigtimebuddy bigtimebuddy left a comment

Choose a reason for hiding this comment

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

Would it be possible to add a simple test for this?

Comment on lines 72 to 73
asset.data = asset.data ?? this.config;
if (asset.data.parseAsGraphicsContext)
Copy link
Member

Choose a reason for hiding this comment

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

Small suggestion to keep asset immutable.

Suggested change
asset.data = asset.data ?? this.config;
if (asset.data.parseAsGraphicsContext)
const data = asset.data ?? this.config;
if (data.parseAsGraphicsContext)

Copy link
Author

Choose a reason for hiding this comment

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

then if would fail in loadAsTexture() line 124 same file. For some reason asset.data is not set when loading an svg through a spritesheet (if i load the same svg file using await Asset.load("svgfile.svg") asset.data is there). I dont think adding this would break anything (it's just meta data).

Copy link
Author

Choose a reason for hiding this comment

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

I was trying to add a test case but I am not able to run the test suit for some reason. It just stuck here
image

I ran npm run start to build then ran npm test. I don't know what I am missing any suggestions?

I also tried running the test file i need directly, same thing.
image

Copy link
Author

Choose a reason for hiding this comment

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

then if would fail in loadAsTexture() line 124 same file. For some reason asset.data is not set when loading an svg through a spritesheet (if i load the same svg file using await Asset.load("svgfile.svg") asset.data is there). I dont think adding this would break anything (it's just meta data).

asset = await parser.load(url, data, this);

this line does not add data to asset for some reason

Copy link
Member

Choose a reason for hiding this comment

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

If we need to reassign asset.data it means there's likely some other problem upstream from this.

Copy link
Author

Choose a reason for hiding this comment

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

Small suggestion to keep asset immutable.

done

Copy link
Author

Choose a reason for hiding this comment

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

@bigtimebuddy let me know if this looks good

Copy link
Author

Choose a reason for hiding this comment

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

@bigtimebuddy added a test case, but i can't run them so not sure if it's correct (it looks like it should pass)

Copy link

codesandbox-ci bot commented Jun 5, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 34276d7:

Sandbox Source
pixi.js-sandbox Configuration

Copy link

codesandbox-ci bot commented Jun 5, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 150deeb:

Sandbox Source
pixi.js-sandbox Configuration

Copy link

codesandbox-ci bot commented Jun 5, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ab07198:

Sandbox Source
pixi.js-sandbox Configuration

Copy link

codesandbox-ci bot commented Jun 5, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 29c3727:

Sandbox Source
pixi.js-sandbox Configuration

@bigtimebuddy
Copy link
Member

Thanks for the test case. I talked with @Zyie about this earlier and we agreed that there is something upstream that needs to be fixed. asset.data should exist. He thought it might be because the spritesheet images go through the loader.load() not through Assets.load(). That might account for the difference in not setting the data. Either way, that's probably the correct fix.

@AnkushSarkar10
Copy link
Author

image

I think we just need to call this at some point upstream (maybe right before the parser.load??).

This is from Assets.ts

@bigtimebuddy @Zyie

@AnkushSarkar10
Copy link
Author

any updates on this @bigtimebuddy @Zyie

Copy link

codesandbox-ci bot commented Jun 22, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit dbdf200:

Sandbox Source
pixi.js-sandbox Configuration

@AnkushSarkar10
Copy link
Author

@bigtimebuddy @Zyie fixed upsteam

@AnkushSarkar10
Copy link
Author

image

@Zyie
Copy link
Member

Zyie commented Jul 5, 2024

Closing this in favor of #10694 as it more directly fixes the issue, but thank you for pointing me in the right direction!

@Zyie Zyie closed this Jul 5, 2024
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.

None yet

3 participants