title: AssetManager textures giving black rectangles
body: <p>I got to that point when I have to replace all <code>new Sprite(texture)</code> with <code>new Sprite(manager.get(imgPath,Texture.class))</code> in order to optimize sprites creating and do all the loading before starting the game.</p>
  
  <p>The problem is that when I use a common AssetManager to load all textures I get black rectangles. </p>
  
  <p>Still, using a new AssetManager() each time I need to load a Texture works fine (maybe because this manager is quickly garbadge-collected and doesn't have time to dispose the texture it created?) but that way there is no point of using it.</p>
  
  <p>The setupBody() method below is called at the end of my sprite-body wrapper constructor.</p>
  
  <p>the working code (yet useless) ─ one new AssetManager for each sprite:</p>
  
  <pre><code>protected void setupBody(String path){
      BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal(path));
      BodyDef bDef = new BodyDef();
      bDef.type = BodyDef.BodyType.DynamicBody;
      bDef.position.set(this.position);
      bDef.angle = this.rotation;
      body = mWorld.createBody(bDef);
      body.setUserData(this);
      FixtureDef fix = new FixtureDef();
      fix.density = 0.1f;
      fix.friction = 0f;
      fix.restitution = 0.5f;
      fix.filter.categoryBits = this.getCategory();
      fix.filter.maskBits = this.getMask();
      origin = loader.getOrigin("base"+identifier, 1).cpy();
      String imgPath = loader.getImagePath("base"+identifier);
  
      AssetManager manager = new AssetManager();
      manager.load(imgPath,Texture.class);
      manager.finishLoading();
      Texture baseSpriteTexture = manager.get(imgPath,Texture.class);
      Texture baseSpriteTexture = new Texture(imgPath);
      baseSprite = new Sprite(baseSpriteTexture);
  
      loadHighlightedSprite(loader, identifier);
      attachFixture(loader, identifier, fix);
  }
  </code></pre>
  
  <p>the code keeping me sleepless ─ the idea is to have a single non-static manager :</p>
  
  <pre><code>protected void setupBody(String path){
      /*no changes before */
      String imgPath = loader.getImagePath("base"+identifier);
  
      AssetManager manager = SmallIntestineDemoGame.getAssets();
  
      manager.load(imgPath,Texture.class);
      /* no changes after */
  }
  </code></pre>
  
  <p>SmallIntestineDemoGame$getAssets() :</p>
  
  <pre><code>public class SmallIntestineDemoGame extends Game {
  
      public AssetManager assets;
  
  
  
      @Override
      public void create() {
          setScreen(new GameScreen());
      }
  
      public static AssetManager getAssets() {
          return ((SmallIntestineDemoGame) Gdx.app.getApplicationListener()).assets;
      }
  
      public void setupAssets(){
          this.assets = new AssetManager();
          Texture.setAssetManager(assets);
      }
  
  }
  </code></pre>
  
  <p>DEBUGGING :</p>
  
  <p>Debugging my asset manager got me confused. size of values of values of assets map of manager gets stuck at 33 even if I'm adding more:</p>
  
  <p><a href="https://i.stack.imgur.com/zoHkS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zoHkS.jpg" alt=""></a><br>
  <sub>(source: <a href="https://img11.hostingpics.net/pics/7064181699775810210795468115381848484959122300413n.jpg" rel="nofollow noreferrer">hostingpics.net</a>)</sub>  </p>
  
  <p>I tested both cases ─ the app with a new AssetManager() (followed by finishloading and all required stuff) for each sprite creation. AND with a unique asset manager passed to all sprite creations :</p>
  
  <p>I set a breakpoint at draw method and there was almost no difference between the two sprites, except for sprite.texture.glhandle ! 
  When all sprites textures are created using the same manager their textures glhandle is set to 0 and this explains the black rectangles. But when each sprite is created using a locally newly created asset manager, the glhandle has some proper value (2269).</p>