Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Basic Camera App only works once in KitchenSink

Dear community / support,

I have a problem with the camera app on an android emulator. I achieve the same behaviour on my own written app and the KitchenSink app.

The 'Basic Camera' application runs only once. After a second trial the camera returns no image.

So what am I doing:
Starting the emulator, starting KitchenSink App, going to 'Phone' -> 'Camera' -> 'Camera Basic':
Now I start the Camera, take a photo and the photo is displayed centered in the window. For logs see Reference 1 @ gist.github.

Now I go back one screen and Start Camera Basic a second time: Take a photo, press OK and the Screen returns to an empty (black) screen. For logs see Reference 2 @ gist.github.

Current version i tested with is appcelerator-KitchenSink-1.4.0-0-g4a68136.zip, running with APIs 1.6 on WVGA800 Android Emulator.

I wonder about line 59 and 60 in the second log snapshot:

[..]
48: [TRACE] D/CameraService( 31): startPreview (pid 256)
49: [TRACE] D/CameraService( 31): startCameraMode(0) (pid 256)
[..]
59: [TRACE] D/Camera-JNI( 224): release camera
60: [TRACE] D/Camera-JNI( 224): release camera
61: [TRACE] D/dalvikvm( 147): GC freed 2071 objects / 95056 bytes in 666ms
62: [TRACE] V/camera ( 256): Start autofocus.
63: [TRACE] D/CameraService( 31): autoFocus (pid 256)
[..]
70: [TRACE] D/CameraService( 31): takePicture (pid 256)
71: [TRACE] D/CameraService( 31): postShutter
72: [TRACE] D/CameraService( 31): postRaw
73: [TRACE] D/CameraService( 31): postJpeg
74: [TRACE] D/Camera-JNI( 256): dataCallback(8, 0x24d220)

Why is the camera released before starting autofocus and taking the picture? This is not the case in the first trial.

Another point: An excpetion is thrown in the finalization of the first trial. This exception is not thrown always. Starting the scenario a second time was finished without this exception.

[TRACE] I/dalvikvm( 52): Uncaught exception thrown by finalizer (will be discarded):
[TRACE] I/dalvikvm( 52): Ljava/io/IOException;:
[TRACE] I/dalvikvm( 52): at org.apache.harmony.luni.platform.OSFileSystem.close(OSFileSystem.java:212)
[TRACE] I/dalvikvm( 52): at java.io.FileInputStream.close(FileInputStream.java:196)
[TRACE] I/dalvikvm( 52): at java.io.FileInputStream.finalize(FileInputStream.java:213)
[TRACE] I/dalvikvm( 52): at dalvik.system.NativeStart.run(Native Method)

No callback function is called when the camera is closed a second time. Not cancel, not success not error. The camera window closes but the camera process is still open in the task-manager, which is NOT the case after the first trial. Their the camera process obviously gets terminated.

Obviously the rewind process from the camera back to the application is only working once. No callbacks are called and the camera process keeps running.

Any clue what is going wrong here? Maybe wrong usage or a SDK Bug?

Help is appreciated, since we need this feature urgently and not only once ;)

Best regards

Christian

— asked September 30th 2010 by Christian Bartels
  • android
  • basic
  • camera
  • emulator
  • error
  • fine
  • kitchensink
  • mobile
  • one
  • running
  • second
  • trial
  • twice
0 Comments

6 Answers

  • First try a Continuous Integration build. We've fixed several memory issues and event handlers.

    — answered September 30th 2010 by Don Thorp
    permalink
    0 Comments
  • Thank you for this hint. I tried it with the latest build:

    mobilesdk-1.4.2-20100930171026-win32.zip

    Now it is working twice, which is better then before ;) but trying it a third time leads to following Exception:

    [TRACE] V/camera ( 241): startPreview
    [TRACE] D/CameraService( 31): startPreview (pid 241)
    [TRACE] D/CameraService( 31): startCameraMode(0) (pid 241)
    [TRACE] D/CameraService( 31): mSurface is not set yet.
    [TRACE] D/CameraService( 31): startPreviewMode (pid 241)
    [TRACE] D/Camera-JNI( 241): dataCallback(4, 0x155450)
    [TRACE] V/camera ( 241): Got first frame
    [TRACE] W/IInputConnectionWrapper( 189): showStatusIcon on inactive InputConnection
    [TRACE] E/IMemory ( 241): binder=0x24e8d0 transaction failed fd=-2147483647, size=0, err=-2147483646 (Unknown error: 2147483646)
    [TRACE] E/IMemory ( 241): cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
    [TRACE] E/IMemory ( 241): cannot map BpMemoryHeap (binder=0x24e8d0), size=0, fd=-1 (Bad file number)
    [TRACE] E/Surface ( 241): Couldn't map Surface's heap (binder=0x24e8d0, heap=0x2c2a20)
    [TRACE] E/ViewRoot( 241): IllegalArgumentException locking surface
    [TRACE] E/ViewRoot( 241): java.lang.IllegalArgumentException
    [TRACE] E/ViewRoot( 241): at android.view.Surface.lockCanvasNative(Native Method)
    [TRACE] E/ViewRoot( 241): at android.view.Surface.lockCanvas(Surface.java:275)
    [TRACE] E/ViewRoot( 241): at android.view.ViewRoot.draw(ViewRoot.java:1266)
    [TRACE] E/ViewRoot( 241): at android.view.ViewRoot.performTraversals(ViewRoot.java:1097)
    [TRACE] E/ViewRoot( 241): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613)
    [TRACE] E/ViewRoot( 241): at android.os.Handler.dispatchMessage(Handler.java:99)
    [TRACE] E/ViewRoot( 241): at android.os.Looper.loop(Looper.java:123)
    [TRACE] E/ViewRoot( 241): at android.app.ActivityThread.main(ActivityThread.java:4203)
    [TRACE] E/ViewRoot( 241): at java.lang.reflect.Method.invokeNative(Native Method)
    [TRACE] E/ViewRoot( 241): at java.lang.reflect.Method.invoke(Method.java:521)
    [TRACE] E/ViewRoot( 241): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    [TRACE] E/ViewRoot( 241): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
    [TRACE] E/ViewRoot( 241): at dalvik.system.NativeStart.main(Native Method)
    [TRACE] I/ActivityManager( 53): Displayed activity com.android.camera/.Camera: 2484 ms (total 2484 ms)
    [TRACE] D/dalvikvm( 53): GC freed 930 objects / 42896 bytes in 220ms
    [TRACE] D/dalvikvm( 148): GC freed 297 objects / 12752 bytes in 225ms
    [TRACE] D/dalvikvm( 92): GC freed 12250 objects / 692280 bytes in 459ms
    [TRACE] D/dalvikvm( 53): threadid=17: bogus mon 1+0>0; adjusting
    [TRACE] E/IMemory ( 241): binder=0x24e8d0 transaction failed fd=-2147483647, size=0, err=-2147483646 (Unknown error: 2147483646)
    [TRACE] E/IMemory ( 241): cannot dup fd=-2147483647, size=0, err=-2147483646 (Bad file number)
    [TRACE] E/IMemory ( 241): cannot map BpMemoryHeap (binder=0x24e8d0), size=0, fd=-1 (Bad file number)
    [TRACE] E/Surface ( 241): Couldn't map Surface's heap (binder=0x24e8d0, heap=0x2c2a20)
    [TRACE] E/ViewRoot( 241): IllegalArgumentException locking surface
    [TRACE] E/ViewRoot( 241): java.lang.IllegalArgumentException
    [TRACE] E/ViewRoot( 241): at android.view.Surface.lockCanvasNative(Native Method)
    [TRACE] E/ViewRoot( 241): at android.view.Surface.lockCanvas(Surface.java:275)
    [TRACE] E/ViewRoot( 241): at android.view.ViewRoot.draw(ViewRoot.java:1266)
    [TRACE] E/ViewRoot( 241): at android.view.ViewRoot.performTraversals(ViewRoot.java:1097)
    [TRACE] E/ViewRoot( 241): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613)
    [TRACE] E/ViewRoot( 241): at android.os.Handler.dispatchMessage(Handler.java:99)
    [TRACE] E/ViewRoot( 241): at android.os.Looper.loop(Looper.java:123)
    [TRACE] E/ViewRoot( 241): at android.app.ActivityThread.main(ActivityThread.java:4203)
    [TRACE] E/ViewRoot( 241): at java.lang.reflect.Method.invokeNative(Native Method)
    [TRACE] E/ViewRoot( 241): at java.lang.reflect.Method.invoke(Method.java:521)
    [TRACE] E/ViewRoot( 241): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    [TRACE] E/ViewRoot( 241): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
    [TRACE] E/ViewRoot( 241): at dalvik.system.NativeStart.main(Native Method)
    

    Looks like another memory lack. Any ideas?

    Christian

    — answered October 1st 2010 by Christian Bartels
    permalink
    0 Comments
  • That looks like an Android bug. It's dying in the camera while it's trying to display the preview I think. The camera code in the emulator is buggy. Can you try it on devices?

    — answered October 1st 2010 by Don Thorp
    permalink
    0 Comments
  • I currently do not have a physical device to test it on. I will keep you updated once I get one.

    Thanks for the support so far ;)

    — answered October 4th 2010 by Christian Bartels
    permalink
    0 Comments
  • This is not only happening on Android. It also happens on iOS specifically on iPhone/iPod 4
    Check this one http://developer.appcelerator.com/question/62721/app-rejected—camera-crashes-app-on-iphone4–ios-41

    — answered October 29th 2010 by Awesome Dude
    permalink
    0 Comments
  • Android camera still has issues! Success Event doesn't always fire…very random.

    — answered June 23rd 2011 by Brian Dittmer
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.