简体   繁体   中英

Why won't my android assets load after first run?

I am writing an android app using the LibGDX framework. I'm currently running into an issue where after I have installed my app (via Eclipse or manually by using the .apk installer) certain .png assets won't render to the screen.

After doing the initial install, everything works as expected on the first run. After that however, some of my assets won't render. There are no exceptions; the images are loaded, they just aren't rendered to the screen. I have inspected the installed .apk in /data/app/<appname> , and the texture pack file and image I am using are both there, and look as they should.

The code for creating the pack file was copied from another project I wrote, and the implementation of the texture loading is identical. All of the dependencies and api versions are identical between those two projects, and I am only experiencing this on the new app.

As soon as I use the eclipse debugger to run and observe the program, the .apk is reloaded, and thus the issue goes away ... for that first run. I have also tried reinstalling the .apk located in /data/app , and then the program will work ... for that first run.

I have tried re-exporting the offending .png files as new .png s, and that doesn't help. I have tried exporting them as .jpg s, and that doesn't help. This is causing me to pull my hair out! Does anyone know what the issue could be?

Edit:

Game.java

...
@Override
public void create() {
    TEXTURES = new TextureAtlas(Gdx.files.internal("textures/textures.pack"));
    WIDTH = Gdx.app.getGraphics().getWidth();
    HEIGHT = Gdx.app.getGraphics().getHeight();
    this.setScreen(new IntroScreen());
    startTime = System.currentTimeMillis();
}
...

ButtonRenderer.java

...
private ButtonRenderer() {
    playButton = createButton("play", "play_dark", "play_dark",
            buttonSize, buttonSize);
    pauseButton = createButton("pause", "pause_dark", "pause_dark",
            buttonSize, buttonSize);
    stopButton = createButton("stop", "stop_dark", "stop_dark",
            buttonSize, buttonSize);
    recordButton = createButton("record", "record_dark", "record_dark",
            buttonSize, buttonSize);
    addButtons(playButton, pauseButton, stopButton, recordButton);
}

private ImageButton createButton(String iconName, String downIconName, String checkedIconName,
        int width, int height) {
    Sprite defaultSprite = Game.TEXTURES.createSprite(iconName);
    defaultSprite.setSize(width, height);
    SpriteDrawable defaultDrawable = new SpriteDrawable(defaultSprite);

    Sprite downSprite = Game.TEXTURES.createSprite(downIconName);
    downSprite.setSize(width, height);
    SpriteDrawable downDrawable = new SpriteDrawable(downSprite);

    Sprite checkedSprite = Game.TEXTURES.createSprite(checkedIconName);
    checkedSprite.setSize(width, height);
    SpriteDrawable checkedDrawable = new SpriteDrawable(checkedSprite);

    return new ImageButton(defaultDrawable, downDrawable, checkedDrawable);
}

public void addButtons(ImageButton... buttons) {
    for (ImageButton button : buttons) {
        addButton(button);
    }
}

public void addButton(ImageButton button) {
    buttons.add(button);
    stage.addActor(button);
    button.setPosition(buttonSize * this.buttons.size(), 0);
    button.setSize(buttonSize, buttonSize);
    button.pack();
}

public void render(float delta, GL20 gl) {
    stage.act(delta);
    batch.begin();
    stage.draw();
    batch.end();
}
...

Log

10-19 20:40:18.423: D/Sampling Rate Check(14289): Attempting rate 44100Hz, bits: 2, channel: 12
10-19 20:40:18.623: I/AndroidInput(14289): sensor listener setup
10-19 20:40:18.723: W/GL2JNIView(14289): creating OpenGL ES 2.0 context
10-19 20:40:18.743: I/AndroidGraphics(14289): OGL renderer: NVIDIA Tegra
10-19 20:40:18.743: I/AndroidGraphics(14289): OGL vendor: NVIDIA Corporation
10-19 20:40:18.743: I/AndroidGraphics(14289): OGL version: OpenGL ES 2.0
10-19 20:40:18.743: I/AndroidGraphics(14289): OGL extensions: GL_NV_platform_binary GL_OES_rgb8_rgba8 GL_OES_fbo_render_mipmap GL_NV_depth_nonlinear GL_NV_draw_path GL_OES_EGL_image GL_OES_vertex_half_float GL_NV_framebuffer_vertex_attrib_array GL_NV_coverage_sample GL_OES_mapbuffer GL_ARB_draw_buffers GL_EXT_Cg_shader GL_EXT_packed_float GL_OES_texture_half_float GL_OES_texture_float GL_EXT_texture_array GL_OES_compressed_ETC1_RGB8_texture GL_EXT_texture_compression_latc GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_s3tc GL_EXT_texture_filter_anisotropic GL_NV_get_tex_image GL_NV_read_buffer GL_NV_shader_framebuffer_fetch GL_NV_fbo_color_attachments GL_EXT_bgra GL_EXT_texture_format_BGRA8888 GL_EXT_unpack_subimage 
10-19 20:40:18.753: I/AndroidGraphics(14289): framebuffer: (5, 6, 5, 0)
10-19 20:40:18.753: I/AndroidGraphics(14289): depthbuffer: (16)
10-19 20:40:18.753: I/AndroidGraphics(14289): stencilbuffer: (0)
10-19 20:40:18.753: I/AndroidGraphics(14289): samples: (0)
10-19 20:40:18.753: I/AndroidGraphics(14289): coverage sampling: (false)
10-19 20:40:18.753: I/AndroidGraphics(14289): Managed meshes/app: { }
10-19 20:40:18.753: I/AndroidGraphics(14289): Managed textures/app: { }
10-19 20:40:18.763: I/AndroidGraphics(14289): Managed shaders/app: { }
10-19 20:40:18.763: I/AndroidGraphics(14289): Managed buffers/app: { }
10-19 20:40:24.943: I/AndroidGraphics(14289): paused
10-19 20:40:25.033: I/AndroidInput(14289): sensor listener tear down
10-19 20:40:25.033: I/AndroidGraphics(14289): Managed meshes/app: { }
10-19 20:40:25.033: I/AndroidGraphics(14289): Managed textures/app: { }
10-19 20:40:25.033: I/AndroidGraphics(14289): Managed shaders/app: { }
10-19 20:40:25.033: I/AndroidGraphics(14289): Managed buffers/app: { }
10-19 20:40:25.033: I/AndroidGraphics(14289): destroyed
10-19 20:40:25.413: W/IInputConnectionWrapper(14289): showStatusIcon on inactive InputConnection

原来应用程序进程在后台运行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM