Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ruspa

Pages: [1]
1
Support / Re: EGL_BAD_SURFACE after some orientation changes
« on: March 05, 2016, 04:37:09 pm »
I probably have to deal with "fragments" [insert WAT meme here] as mentioned here https://stackoverflow.com/questions/7128670/best-practice-asynctask-during-orientation-change. Or find a cool way to pin my wallpaper in portrait like forever.

"Caution: While you can store any object, you should never pass an object that is tied to the Activity, such as a Drawable, an Adapter, a View or any other object that's associated with a Context. If you do, it will leak all the views and resources of the original activity instance. (Leaking resources means that your application maintains a hold on them and they cannot be garbage-collected, so lots of memory can be lost.)"

Fragments. Fragments of the weekend that ... pfff... evaporate :D :D :D

2
Support / Re: EGL_BAD_SURFACE after some orientation changes
« on: March 05, 2016, 04:11:47 pm »
Probably they are, seems reasonable. But I cannot easily debug on my device (with breakpoints and all the frills) to prove it, sometime works but most of the time it doesn't connect to the debugger. Since gradle/android studio at least, it could do it easier in eclipse.

I provided a stripped code of my 2 classes. I removed every chunk of code that looked totally unrelated to the issue (sensors reading, rotation matrix calculations and stuff) I think that android system recreates the wallpaper "almost completely" every time you rotate the device, leaving you with bits of the older activities still running or interfering with the newer one.
Or it can be the 2/3 second lag that the wallpaper picker has when switching orientation? I wonder why these errors (and the resulting bad rotation readings, basically the app is a sphere doing the compass, just in 3d and without gymbal lock) are incremental.
Perhaps there's a clever way to store and reuse previously created engines and to pass it again once the OS recreates the activity... but the openGL world and its statemachine is still black magic to me. By googling I found out this error (or pretty similar) is not new to the developers, but most of the times the solution they give is to lock the app in a fixed orientation. But I can't! :(

Main class:
Code: [Select]



public class myBallObjectWPService extends GLWallpaperService{

   

   

    public myBallObjectWPService(){
        super();
        android.os.Debug.waitForDebugger();

    }


    public Engine onCreateEngine() {


       if(engine!=null){
            engine.onDestroy();
            engine=null;
       }
        engine = new MyEngine(this);
        return engine;

    }





    class MyEngine extends GLEngine implements SensorEventListener{

        MyRenderer renderer;
        Context _context;



        @Override
        public void onCreate(SurfaceHolder surfaceHolder) {
            super.onCreate(surfaceHolder);
            initializeSensors();
        }

        @Override
        public void onDestroy() {


            if (renderer != null) {
                renderer.release();
            }
            renderer = null;

            super.onDestroy();


        }
        @Override
        public void onResume() {
            super.onResume();
        }

        @Override
        public void onPause() {
            super.onPause();
        }


     




        @Override
        public void onSensorChanged(SensorEvent event) {


     

            if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
               
synchronized (mRotationMatrix) {

//[do axes remap and sensor readings]

                }


        }



        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }



        public MyEngine(Context context) {

            _context = context;


            if(renderer!=null){
                renderer.release();
                renderer=null;
            }
            renderer = new MyRenderer(_context);
            setRenderer(renderer);
            setRenderMode(RENDERMODE_CONTINUOUSLY);



        }



}


Rendering class:
Code: [Select]

public class MyRenderer implements GLWallpaperService.Renderer {



    public MyRenderer(Context context) {


        if(myBallObjectWPService.renderer!=null){
            return;
        }

        GLSurfaceView mGLView = new GLSurfaceView(context);
        mGLView.setEGLContextClientVersion(2);
        _context = context;



    }



    public void onSurfaceChanged(GL10 gl, int w, int h) {



     
createObjects();

        if (fb != null) {
            fb.dispose();
        }
        fb = new FrameBuffer(gl, w, h);


Logger.log("creating world", Logger.WARNING);

world = new World();
world.setAmbientLight(100, 100, 100);

world.addObject(myBallObject);
cam = world.getCamera();

cam.moveCamera(Camera.CAMERA_MOVEOUT, myZoom);



SimpleVector sv = new SimpleVector();
sv.y -= 1600;
sv.z = 1600;
sv.x = -1600;
sun = new Light(world);
sun.setIntensity(250, 250, 250);
sun.setPosition(sv);


            MemoryHelper.compact();


        }
    }



    public void onSurfaceCreated(GL10 gl, EGLConfig config) {



        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setTypeface(Typeface.create((String) null, Typeface.BOLD));

        paint.setTextSize(50);
        glFont = new AGLFont(paint);

        paint.setTextSize(300);


    }





    public void onDrawFrame(GL10 gl) {





        synchronized (myBallObjectWPService.mRotationMatrix) {
            myBallObject.clearRotation();
            m = new Matrix();
            m.setDump(myBallObjectWPService.mRotationMatrix);
            myBallObject.setRotationMatrix(m);
        }


        fb.clear(back);
        world.renderScene(fb);
        world.draw(fb);
        fb.display();

    }


    public void release() {
    }

   

private void loadTextures(){


}
   
   

    private createObjectsAndTextures() {

        if ( !TextureManager.getInstance().containsTexture( "myBallObjecttex_1" ) ) {
            myBallObjectTexture_1 = new Texture(BitmapHelper.rescale(BitmapHelper.convert(ContextCompat.getDrawable(_context, R.raw.myBallObjecttex2)), 1024, 512));
            TextureManager.getInstance().addTexture("myBallObjecttex_1", myBallObjectTexture_1);
        }

myBallObject = ExtendedPrimitives.createEllipsoid(new SimpleVector(305, 305, 305), 64, 1f, 1f);


        myBallObject.setTexture("myBallObjecttex_1");
       

        myBallObject.rotateX((float) Math.toRadians(-90));
        myBallObject.rotateZ((float) Math.toRadians(90));
        myBallObject.rotateMesh();
        myBallObject.compile(true);

        myBallObject.calcNormals();
        myBallObject.strip();
       

        myBallObject.build();
    }


}

3
Support / EGL_BAD_SURFACE after some orientation changes
« on: March 05, 2016, 03:02:22 pm »
hello, anyone had issues after you've changed screen orientation a few times? Especially maybe with wallpapers based on GLSurfaceView(http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers)?
I'd have preferred to force my app not to change orientation in any case, but since it's a live wallpaper I really cannot do it. You can always change the orientation of LWP in the wallpaper gallery menu, for instance, or if you have a phone with a switchblade-like side keyboard.

After a couple of times I reorient the device (and my lwp as well), or locking and unlocking very quickly, I start getting wobbles and flickers in my rendering, and in the logcat i see errors like this.

Code: [Select]
E/Surface: queueBuffer: error queuing buffer to SurfaceTexture, -19
W/Adreno-EGLSUB: <SwapBuffers:1345>: failed to queueBuffer
W/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3888>: EGL_BAD_SURFACE
W/Adreno-EGLSUB: <DequeueBuffer:721>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
W/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3792>: EGL_BAD_SURFACE

over and over again. At the beginning just a few. The more you keep reorienting, the more the render engine gets recreated and the more same idendical errors flow on the log.

Is this something due to previus-orientation instances still trying to render on null surfaceviews? I tried my best to not recreate everything at any rotation change but this occurs nevertheless. See the formatted log  ???

Code: [Select]
03-05 14:58:34.468 24653-24653/jPCT-AE: [ 1457186314468 ] - WARNING: MyRenderer() NEW <-----
03-05 14:58:34.485 24653-24653/jPCT-AE: [ 1457186314485 ] - WARNING: WPService.MyEngine() NEW <---
03-05 14:58:34.737 24653-24653/jPCT-AE: [ 1457186314737 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:34.738 24653-24653/jPCT-AE: [ 1457186314738 ] - WARNING: pause
03-05 14:58:34.740 24653-24653/jPCT-AE: [ 1457186314740 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:34.808 24653-24676/jPCT-AE: [ 1457186314808 ] - WARNING: creating textures ****************************************************************************
03-05 14:58:35.228 24653-24676/jPCT-AE: [ 1457186315228 ] - WARNING: creating  object
03-05 14:58:35.355 24653-24676/jPCT-AE: [ 1457186315355 ] - WARNING: creating world
03-05 14:58:35.358 24653-24676/jPCT-AE: [ 1457186315358 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:35.358 24653-24676/jPCT-AE: [ 1457186315358 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:35.358 24653-24676/jPCT-AE: [ 1457186315358 ] - WARNING: -420 0 45.0
03-05 14:58:35.358 24653-24676/jPCT-AE: [ 1457186315358 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:38.596 24653-24653/jPCT-AE: [ 1457186318596 ] - WARNING: WPService.MyEngine.onSensorChanged > portrait: true
03-05 14:58:38.663 24653-24653/jPCT-AE: [ 1457186318663 ] - WARNING: pause
03-05 14:58:38.882 24653-24653/jPCT-AE: [ 1457186318882 ] - WARNING: MyRenderer() NEW <-----
03-05 14:58:38.882 24653-24653/jPCT-AE: [ 1457186318882 ] - WARNING: WPService.MyEngine() NEW <---
03-05 14:58:38.899 24653-24653/jPCT-AE: [ 1457186318899 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:38.899 24653-24653/jPCT-AE: [ 1457186318899 ] - WARNING: pause
03-05 14:58:38.905 24653-24653/jPCT-AE: [ 1457186318905 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:38.944 24653-24846/jPCT-AE: [ 1457186318944 ] - WARNING: creating textures ****************************************************************************
03-05 14:58:38.944 24653-24846/jPCT-AE: [ 1457186318944 ] - WARNING: creating  object
03-05 14:58:39.093 24653-24846/jPCT-AE: [ 1457186319093 ] - WARNING: creating world
03-05 14:58:39.094 24653-24846/jPCT-AE: [ 1457186319094 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:39.094 24653-24846/jPCT-AE: [ 1457186319094 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:39.094 24653-24846/jPCT-AE: [ 1457186319094 ] - WARNING: -420 0 45.0
03-05 14:58:39.094 24653-24846/jPCT-AE: [ 1457186319094 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:43.830 24653-24653/jPCT-AE: [ 1457186323830 ] - WARNING: WPService.MyEngine.onSensorChanged > portrait: false
03-05 14:58:43.961 24653-24653/jPCT-AE: [ 1457186323961 ] - WARNING: pause
03-05 14:58:44.067 24653-24653/jPCT-AE: [ 1457186324067 ] - WARNING: MyRenderer() NEW <-----
03-05 14:58:44.068 24653-24653/jPCT-AE: [ 1457186324068 ] - WARNING: WPService.MyEngine() NEW <---
03-05 14:58:44.089 24653-24653/jPCT-AE: [ 1457186324089 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:44.089 24653-24653/jPCT-AE: [ 1457186324089 ] - WARNING: pause
03-05 14:58:44.101 24653-24653/jPCT-AE: [ 1457186324101 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:44.141 24653-24976/jPCT-AE: [ 1457186324141 ] - WARNING: creating textures ****************************************************************************
03-05 14:58:44.141 24653-24976/jPCT-AE: [ 1457186324141 ] - WARNING: creating  object
03-05 14:58:44.283 24653-24976/jPCT-AE: [ 1457186324283 ] - WARNING: creating world
03-05 14:58:44.284 24653-24976/jPCT-AE: [ 1457186324284 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:44.284 24653-24976/jPCT-AE: [ 1457186324284 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:44.285 24653-24976/jPCT-AE: [ 1457186324284 ] - WARNING: -420 0 45.0
03-05 14:58:44.285 24653-24976/jPCT-AE: [ 1457186324285 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:53.901 24653-24653/jPCT-AE: [ 1457186333901 ] - WARNING: WPService.MyEngine.onSensorChanged > portrait: true
03-05 14:58:54.058 24653-24976/Adreno-EGLSUB: <DequeueBuffer:721>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
03-05 14:58:54.058 24653-24976/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3792>: EGL_BAD_SURFACE
03-05 14:58:54.108 24653-24976/Adreno-EGLSUB: <DequeueBuffer:721>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
03-05 14:58:54.108 24653-24976/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3792>: EGL_BAD_SURFACE
03-05 14:58:54.152 24653-24653/jPCT-AE: [ 1457186334152 ] - WARNING: pause
03-05 14:58:54.192 24653-24653/jPCT-AE: [ 1457186334192 ] - WARNING: MyRenderer() NEW <-----
03-05 14:58:54.193 24653-24653/jPCT-AE: [ 1457186334193 ] - WARNING: WPService.MyEngine() NEW <---
03-05 14:58:54.221 24653-24653/jPCT-AE: [ 1457186334221 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:54.221 24653-24653/jPCT-AE: [ 1457186334221 ] - WARNING: pause
03-05 14:58:54.238 24653-24653/jPCT-AE: [ 1457186334238 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:54.263 24653-25237/jPCT-AE: [ 1457186334263 ] - WARNING: creating textures ****************************************************************************
03-05 14:58:54.263 24653-25237/jPCT-AE: [ 1457186334263 ] - WARNING: creating  object
03-05 14:58:54.409 24653-25237/jPCT-AE: [ 1457186334409 ] - WARNING: creating world
03-05 14:58:54.410 24653-25237/jPCT-AE: [ 1457186334410 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:54.410 24653-25237/jPCT-AE: [ 1457186334410 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:54.410 24653-25237/jPCT-AE: [ 1457186334410 ] - WARNING: -420 0 45.0
03-05 14:58:54.410 24653-25237/jPCT-AE: [ 1457186334410 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:56.132 24653-24653/jPCT-AE: [ 1457186336132 ] - WARNING: WPService.MyEngine.onSensorChanged > portrait: false
03-05 14:58:56.275 24653-25237/Adreno-EGLSUB: <DequeueBuffer:721>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
03-05 14:58:56.275 24653-25237/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3792>: EGL_BAD_SURFACE
03-05 14:58:56.336 24653-25237/Adreno-EGLSUB: <DequeueBuffer:721>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
03-05 14:58:56.336 24653-25237/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3792>: EGL_BAD_SURFACE
03-05 14:58:56.348 24653-25237/Adreno-EGLSUB: <DequeueBuffer:721>: dequeue native buffer fail: No such device, buffer=0x0, handle=0x0
03-05 14:58:56.348 24653-25237/Adreno-EGL: <qeglDrvAPI_eglSwapBuffers:3792>: EGL_BAD_SURFACE
03-05 14:58:56.350 24653-24653/jPCT-AE: [ 1457186336350 ] - WARNING: pause
03-05 14:58:56.456 24653-24653/jPCT-AE: [ 1457186336456 ] - WARNING: MyRenderer() NEW <-----
03-05 14:58:56.457 24653-24653/jPCT-AE: [ 1457186336457 ] - WARNING: WPService.MyEngine() NEW <---
03-05 14:58:56.482 24653-24653/jPCT-AE: [ 1457186336482 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:56.482 24653-24653/jPCT-AE: [ 1457186336482 ] - WARNING: pause
03-05 14:58:56.508 24653-24653/jPCT-AE: [ 1457186336508 ] - WARNING:  WPService.MyEngine.onResume()
03-05 14:58:56.559 24653-25296/jPCT-AE: [ 1457186336559 ] - WARNING: creating textures ****************************************************************************
03-05 14:58:56.559 24653-25296/jPCT-AE: [ 1457186336559 ] - WARNING: creating  object
03-05 14:58:56.749 24653-25296/jPCT-AE: [ 1457186336749 ] - WARNING: creating world
03-05 14:58:56.749 24653-25296/jPCT-AE: [ 1457186336749 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:56.749 24653-25296/jPCT-AE: [ 1457186336749 ] - WARNING: No normals have been calculated for this mesh yet!
03-05 14:58:56.750 24653-25296/jPCT-AE: [ 1457186336750 ] - WARNING: -420 0 45.0
03-05 14:58:56.750 24653-25296/jPCT-AE: [ 1457186336750 ] - WARNING: No normals have been calculated for this mesh yet!

4
Support / Re: model flickering sometimes without errors
« on: March 02, 2016, 08:39:52 pm »
YOU ARE MY HERO  ;D ;D ;D

I'm a j2ee developer, to deal with JBoss Seam, Jbpm and eclipse plugin creation one can happily settle with a poor knowledge of some really basic stuff.
Like this sinchronyzed(something) that with a bit of shame I admit I never had the need to use before.

Just adding

synchronized(rotationMatrix){
                   SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
                    SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_Y, rotationMatrix);
}

in the main activity and

synchronized(MainActivity.rotationMatrix){
                   ball.setRotationMatrix(MainActivity.rotationMatrix);
}

in the render class totally solved the issue.
half bronze star to me for having correct suspects
100 gold stars to you that immediately known the perfect solution

thanks, really!


5
Support / model flickering sometimes without errors
« on: March 02, 2016, 07:00:44 pm »
hello! I'm writing a livewallpaper based on a GLSurfaceRender example for live wallpapers and jpct I found around. It works pretty well except that sometimes the 3d model flickers and stretches randomly for an instant and then works well again for some time.

What I do is loading a sphere model and apply the rotation matrix coming from the Sensors.Type_vector (sorry I know it's incorrect but I'm at a bar at the moment writing this post on my cellphone). I mean the newer sensor reading type that unifies all sensors to avoid gymbal locks.

So in the main activity I register and listen for sensor changes and remap the axes as I see fit. In the render class, in the onDraw method I just apply the rotation matrix and voilą, works like charm.

Now the issue part, that I hope someone can help me fix.

If I do not apply the rotation in the ondraw method the model remains in its initial position and never ever flickers. If I apply (pseudocode) setrotationmatrix(MainActivity.rotationmatrixFromTheSensors) my model rotates very smoothly as you move the phone but suffers of random flickering/tearing/swap to initial position.
On my opinion its something related to desyncronyzation between MainActivity.onSensorChanged() and RenderEngine.onDraw(). Looks like randomly the ondraw method cannot access correctly the rotationmatrix calculated on the main activity, or may be that sensors sometimes actually fails reading data (my phone is a nexus5 in wonderful shape, so it's unlikely the case).

I've tried to be more thread friendly by let the renderer class implement sensorlistener, but then nothing really worked.

Have someone any clue the cause of this random flicker?

I can provide code, or a video of that behavior if it can help.

Thanks in advance guys :)




P.S. If I do not apply the rotation matrix calculated on the main activity and instead apply dummy rotations in the onDraw() method no fllickers occur. These flickers came out only when I applied the rotation matrix from onSensorChanged with the no-gymbal-lock reading. I'm also persuaded that when I've been using the older geomagnetic and accelerometer readings there were no flickers, but I'm not sure. Got to doublecheck as I manage to get home

6
Support / gles2.0 in GLWallpaperService
« on: October 04, 2013, 06:03:32 pm »
Hi there, I successfully merged jpct-ae samples with GLWallpaperService and have my imported .3ds model rotating happily in my homescreen.
Now I want initialize and switch to opengl es2 and found this documentation http://www.jpct.net/wiki/index.php/OpenGL_ES_2.0_support

so I have to do something like this, somewhere:

Code: [Select]

mGLView = new GLSurfaceView(getApplication());   // don't know were to find mGLView..
mGLView.setEGLContextClientVersion(2);

[...]

frameBuffer = new FrameBuffer(/*gl,*/ w, h);    //existing line, commenting only the first parameter obviously blows up everything


the point is that using GLWallpaperService I cannot find any reference to "mGLView" in order to modify it. I think I looked everywhere stepping in debug and I din't see anything similar, so perhaps this might be a bad approach, or I'm just blindfolded...
Where can I get a hook to the mGLView using live wallpapers? Is this approach correct?

Sounds like GLWallpaperService is not based on GLSurfaceView.

Thanks :D

Pages: [1]