DragonBones / DragonBonesJS

DragonBones TypeScript / JavaScript Runtime
MIT License
759 stars 320 forks source link

null exception when destroying/re-creating armatureDisplay #33

Closed spacejack closed 7 years ago

spacejack commented 7 years ago

Hi. First of all, thank you for this PIXI renderer, it's working great for us!

I am trying to understand how to reliably load assets, then dispose of them, then re-load them again.

If I use armature.destroy(true) and then later attempt to re-build the same armature, I get the following error:

Uncaught TypeError: Cannot read property 'hasLoaded' of null
at Sprite.set (pixi.js:21089)

Here is an example: http://www.spacejack.ca/dragonbones-test/

Click "Startup" - load assets, start animatoin Click "Shutdown" - stop animation, dispose of assets Click "Startup" - throws exception

Demo code is here: http://www.spacejack.ca/dragonbones-test/js/app.js

If I change my code to armature.destroy() then it does not crash. Upon re-loading, I get the warning:

Same name data. Zombie_Run
    BaseFactory.addDragonBonesData @ dragonBones.js:9493

I would like to be sure the resources are being desposed of. We're working on a game that contains mini-games, so we need to load the mini-game assets then dispose of them, load a different mini-game, etc.

I'm not sure where the assets are stored from here:

dbFactory.parseDragonBonesData(resources['zombieSkel'].data)
dbFactory.parseTextureAtlasData(resources['zombieAtlas'].data, resources['zombieTex'].texture)
armature = dbFactory.buildArmatureDisplay('Zombie')

Any advice would be much appreciated, thanks.

akdcl commented 7 years ago

Hi, you can dispose armature like this:

armature.dispose();

Dispose dragonBones data like this:

factory.clean();
spacejack commented 7 years ago

Thank you, that works! I'm using:

factory = new dragonBones.PixiFactory()
// Load assets, then...
armature = factory.buildArmatureDisplay(name)
// Later, dispose
armature.dispose()
factory.clear(true)

I assume I can use different factories for different groups of assets.