sourcemars / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

opengl textures not loading #53

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Load an image file from sdcard
2. Run application
3. Application runs fine, all Sprites load correctly.
4. Push back on Device
5. Quickly load up application again.

What is the expected output? What do you see instead?

All Sprites should load correctly.  Instead, the sprites are rendered in all 
white.

What version of the product are you using? On what operating system?
99.7, osx.

Please provide any additional information below.

This is the method I'm using to load the images:

    private static HashMap<String, CCTexture2D> textureMappings = new HashMap<String, CCTexture2D>();

    public static final CCTexture2D addTexture(String filePath) {
        if(filePath.contains("../")) {
            return null;
        }
        CCTexture2D rtn = textureMappings.get(filePath);
        if (rtn == null) {
            String path = Constants.DEFAULT_PATH  + filePath;
            File f = new File(path);
            if (f.exists()) {
                Bitmap bmp = BitmapFactory.decodeFile(Constants.DEFAULT_PATH + filePath);
                rtn = new CCTexture2D(Bitmap.createBitmap(bmp));
                bmp.recycle();
                bmp = null;
                textureMappings.put(filePath, rtn);
            }
        }
        return rtn;
    }

This is the code for my Activity and what I'm doing in my Start and Stop 
methods:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextureMap.init();
        SoundMap.init();
        // set the window status, no tile, full screen and don't sleep
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        mGLSurfaceView = new CCGLSurfaceView(this);
        setContentView(mGLSurfaceView);
    }

    @Override
    public void onPause() {
        super.onPause();
        mGLSurfaceView.onPause();
        CCDirector.sharedDirector().pause();
    }

    @Override
    public void onResume() {
        super.onResume();
        mGLSurfaceView.onResume();
        CCDirector.sharedDirector().resume();
    }

    @Override
    public void onStart() {
        super.onStart();
        // attach the OpenGL view to a window
        CCDirector.sharedDirector().attachInView(mGLSurfaceView);

        // no effect here because device orientation is controlled by manifest
        CCDirector.sharedDirector().setDeviceOrientation(
                CCDirector.kCCDeviceOrientationPortrait);

        // show FPS
        // set false to disable FPS display, but don't delete fps_images.png!!
        CCDirector.sharedDirector().setDisplayFPS(false);

        // frames per second
        CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
        CCScene scene = new IntroScene();
        // Make the Scene active
        CCDirector.sharedDirector().runWithScene(scene);
    }

    @Override
    public void onStop() {
        super.onStop();
        CCDirector.sharedDirector().end();
        mGLSurfaceView.postInvalidate();
        mGLSurfaceView = null;
        this.finish();
    }

Original issue reported on code.google.com by petero...@gmail.com on 14 Feb 2011 at 2:29

GoogleCodeExporter commented 8 years ago
you should better use CCTextureCache.sharedTextureCache().addImage for image 
loading. And HEY, you are using old version. See wiki.

Original comment by opengen...@gmail.com on 14 Feb 2011 at 4:07

GoogleCodeExporter commented 8 years ago
When application pauses OpenGL is destroyed. Then all Images should be 
reloaded. Now this is managed for textures loaded with CCTextureCache. If you 
are loading them manually you have do it somehow (with 
GLResourceHelper.sharedHelper().addLoader for example).  CCTextureCache as I 
know is working with assets paths only. Use assets and CCTextureCache if you 
can. Latest version of cocos2d doesn't have CCTexture2D(Bitmap) constructor.

Original comment by opengen...@gmail.com on 14 Feb 2011 at 4:17

GoogleCodeExporter commented 8 years ago
Working perfectly after applying recommendations.

Wasn't aware of the sharedTextureCache.  The new implementation utilizes it 
along with the addExternalImage method in the build I synced up with today.

I don't believe using assets is an option for me as I would like to allow users 
the ability to upload their own skins to the game.  Are users allowed to 
add/delete/modify asset files?

Thanks for your help.  Please close the bug.

Original comment by petero...@gmail.com on 15 Feb 2011 at 2:41

GoogleCodeExporter commented 8 years ago
Working perfectly after applying recommendations.

Wasn't aware of the sharedTextureCache.  The new implementation utilizes it 
along with the addExternalImage method in the build I synced up with today.

I don't believe using assets is an option for me as I would like to allow users 
the ability to upload their own skins to the game.  Are users allowed to 
add/delete/modify asset files?

Thanks for your help.  Please close the bug.

Original comment by petero...@gmail.com on 15 Feb 2011 at 2:41

GoogleCodeExporter commented 8 years ago
No, assets are closed for user.

Original comment by opengen...@gmail.com on 15 Feb 2011 at 9:51