Mathieu Anthoine Posted June 26, 2017 Share Posted June 26, 2017 Hi, I'm working on changing a personal Loader class that inherits from the Loader PixiJs class. In Pixi v3, I use a middleware called by the after method to add new contents to load during loading and it works very well. When I try to do the same in Pixi v4, this error occurs: "Cannot add resources while the loader is running." Is there a way to do the same thing than in Pixi v3 ? Is it a restriction of Pixi v4 and why ? Thank you for your help Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 26, 2017 Share Posted June 26, 2017 There were some change when we moved to resource-loader v2. Try add "parentResource: resource" to options that you pass to "Add". That's how pixi-spine does it : function (resource) { const atlasOptions = { crossOrigin: resource.crossOrigin, parentResource: resource // <-- this thing }; this.add(resource.name + '_atlas', atlasPath, atlasOptions, onLoad2); // <-- third param! } Quote Link to comment Share on other sites More sharing options...
Mathieu Anthoine Posted June 26, 2017 Author Share Posted June 26, 2017 Ivan, I use Haxe-Pixi, but the syntax is close to what you gave me. There's no longer the error, but the onComplete event is never fired :/ Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 26, 2017 Share Posted June 26, 2017 That wasn't the only thing i had to change in pixi-spine. If you show me the middleware i can guess whats wrong there. Quote Link to comment Share on other sites More sharing options...
Mathieu Anthoine Posted June 26, 2017 Author Share Posted June 26, 2017 Not sure it would be easy to show you the middleware but here the idea: 1) After loading each resource the middleware checks if it is a json that describes a list of sounds 2) if it's the case, the middleware reads the json and add the url of the sound files listed to the loader with add 3) the middleware call the "next" method to continue the loading process. 4) The process of loading continue correctly and seems to stop when it has to load the files added Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 26, 2017 Share Posted June 26, 2017 It should work. oh, sounds. Its better if you ask @xerverand @bigtimebuddy , I summoned them in the topic. But really, please upload an example, on fiddle.jshell.net or in codepen. Quote Link to comment Share on other sites More sharing options...
xerver Posted June 26, 2017 Share Posted June 26, 2017 Hey Mathieu, the loader from v3 and v4 is the same library. You can checkout this post where I explain why you cannot add root resources to the loader while it is loading: https://github.com/pixijs/pixi.js/issues/4100#issuecomment-308200817 Quote Yes, adding a root asset while the loader is running is an error. You can add assets to the loader while it is running, but they must be a child of an existing asset (this is how the spritesheet loader middleware adds image loads based on the json file, for example). What you are doing is pretty similar to the spritesheet loader, you can see what it does here: https://github.com/pixijs/pixi.js/blob/04d187991e8415b027f6e314ba5dc89466231ca7/src/loaders/spritesheetParser.js Restricting loads from middlewares to specify the resource that triggered them fixes a lot of bugs we had before. Quote Link to comment Share on other sites More sharing options...
Mathieu Anthoine Posted June 27, 2017 Author Share Posted June 27, 2017 Thank you xerver for your Help, I tried different things, something close to SpriteSheetParser. I did not have the "cannot add resources" error but stil have a problem, When the Pixi Loader starts to load my additionnal resource, it stops in the Loader.prototype._loadResource, The _onLoad method is never called Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 27, 2017 Share Posted June 27, 2017 Then its something related to the resource type, how loader does with sounds. Is it BLOB or something else? I don't know and I don't have time to look there. Either give me a codepen/fiddle to play, either poke those two guys about sounds. @bigtimebuddy made https://github.com/pixijs/pixi-sound , he knows. One more way - you can just debug the code - use full (not minified) version of pixi and figure out whats wrong there. I think its about format. For example, i choose XHR_TYPE for some things: https://github.com/pixijs/pixi-spine/blob/master/src/loaders.ts#L49 Quote Link to comment Share on other sites More sharing options...
Mathieu Anthoine Posted June 27, 2017 Author Share Posted June 27, 2017 Ivan, I'm working with the full version of pixijs, using chrome debugging tools and breakpoints. About the resource type, Pixi seems to understand correctly the type (AUDIO) I will try to write the code in JS and post it on codepen after. Thank you for your help ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
xerver Posted June 28, 2017 Share Posted June 28, 2017 On 6/27/2017 at 3:05 AM, Mathieu Anthoine said: Thank you xerver for your Help, I tried different things, something close to SpriteSheetParser. I did not have the "cannot add resources" error but stil have a problem, When the Pixi Loader starts to load my additionnal resource, it stops in the Loader.prototype._loadResource, The _onLoad method is never called Sounds like you didn't call the `next()` function properly so your asset never "finished" processing. Please share you middleware code. Quote Link to comment Share on other sites More sharing options...
Mathieu Anthoine Posted June 28, 2017 Author Share Posted June 28, 2017 I have rewrite my code in pure JS and finally it works perfectly with the parentResource. So I need to understand why there's something wrong in my haxe code. Thank you for your help @ivanpopelyshev may be some news about https://github.com/pixijs/pixi.js/issues/3974 ? Quote Link to comment Share on other sites More sharing options...
Mathieu Anthoine Posted June 28, 2017 Author Share Posted June 28, 2017 Ok I found the bug. In my homemade framework, I add a version number at the end of files I want to load: fileName.ext?0.1.0 for example When I add a new file in the loader during loading, if I add an extension to the file, the file is never loaded and the loading never finish When I remove the extension, the loading works well in pure JS or Haxe. In Pixi v3, thje loading was working well even with the version at the end of the filename. Maybe you have changed something in that way ? Do I need to add an issue on github ? PS: Adding a version number after a filename, works well when the files are added before loading, the bug occurs only in the special situation describe above Quote Link to comment Share on other sites More sharing options...
xerver Posted June 28, 2017 Share Posted June 28, 2017 The best thing to do would be to open a PR to resource-loader, where you added a test case that fails. That proves the bug is in the loader, and we can fix the issue and prevent regressions. Quote Link to comment Share on other sites More sharing options...
Mathieu Anthoine Posted June 29, 2017 Author Share Posted June 29, 2017 Here is the issue https://github.com/englercj/resource-loader/issues/94 Thank you xerver Quote Link to comment Share on other sites More sharing options...
xerver Posted June 29, 2017 Share Posted June 29, 2017 This should be fixed in v2.0.9, which I just updated the latest dev of pixi to. It should be in a release with v4.5.4 of pixi. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.