JavaScript How to completely remove Pixi renderer, stage and assets?

I am trying to mount/unmout a Pixi stage with React (I don't want to use react-pixi yet)

I have an error when I re-mount the component:

Uncaught Error: Resource with name "cupCake.png" already exists
i.add.i.enqueueapp.js
componentDidMountmodules.js
_assign.notifyAllmodules.js
ON_DOM_READY_QUEUEING.closemodules.js
Mixin.closeAllmodules.js
Mixin.performmodules.js
Mixin.performmodules.js
_assign.performmodules.js
flushBatchedUpdatesmodules.js
Mixin.closeAllmodules.js
Mixin.performmodules.js
ReactDefaultBatchingStrategy.batchedUpdatesmodules.js
batchedUpdatesmodules.js
ReactEventListener.dispatchEvent

I tried to use: PIXI.TextureCache['cupCake.png'].destroy(true); but the error persists.

Here is my component:

class MapOverlay extends React.Component{

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    this.renderer = PIXI.autoDetectRenderer(256, 256, {transparent: true});
    this.refs.gameCanvas.appendChild(this.renderer.view);

    // create the root of the scene graph
    this.stage = new PIXI.Container();
    this.stage.width = 1366;
    this.stage.height = 768;

    PIXI.loader
      .add("cupCake.png")
      .load(()=> {

        //Create the `cat` sprite from the texture
        var cat = new PIXI.Sprite(
          PIXI.loader.resources["cupCake.png"].texture
        );

        //Add the cat to the stage
        this.stage.addChild(cat);

        //Render the stage
        this.renderer.render(this.stage);
      });
  }

  componentWillUnmount() {
    this.refs.gameCanvas.removeChild(this.renderer.view);
    PIXI.TextureCache['cupCake.png'].destroy(true);
  }

  render() {
    return (
      <div className="game-canvas-container" ref="gameCanvas"></div>
    );
  }
}

So how I could completely reset/delete state and assets?

Answer:1

I want to understand the best way to improve the performance of jQuery code. Actually, I know how to cache the jQuery selectors to not touch the DOM multiple times as follow: The worst way $('....

I want to understand the best way to improve the performance of jQuery code. Actually, I know how to cache the jQuery selectors to not touch the DOM multiple times as follow: The worst way $('....

I'm trying to test protractor on a vanilla.js app and when I run protractor basicConf.js I am getting below error : This webpage is not available ERR_CONNECTION_REFUSED This is my test: describe(...

I'm trying to test protractor on a vanilla.js app and when I run protractor basicConf.js I am getting below error : This webpage is not available ERR_CONNECTION_REFUSED This is my test: describe(...

  1. run protractor config file
  2. run protractor config
  3. protractor run configuration
  4. npm run protractor config file
  5. npm run protractor config

I have created a Simon Game here on Codepen: http://codepen.io/nalexiou/pen/rOaQOK On the desktop, the audio/sound is playing fine. However, when I visit the site using my iPhone's Safari, the sound ...

I have created a Simon Game here on Codepen: http://codepen.io/nalexiou/pen/rOaQOK On the desktop, the audio/sound is playing fine. However, when I visit the site using my iPhone's Safari, the sound ...

I have a one-page website with several anchors (signifying div positions). After the page is resized (change in height only), I want to refresh the page. Then I want to scroll to the anchor the page ...

I have a one-page website with several anchors (signifying div positions). After the page is resized (change in height only), I want to refresh the page. Then I want to scroll to the anchor the page ...