as3 scanHardware() function making my app crash
Asked Answered
D

1

9

I am using ScanHardware function to get the updated Camera list. If plug in a Camera to my Mac mini, Camera length is being updated. If I plug out the Camera My app closes abruptly.

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       height="280"
                       width="280"
                       creationComplete="test1()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[

            import mx.controls.Alert;
            public var hardwareTimer:Timer;
            public function test1():void{
                hardwareTimer = new Timer(5000);
                hardwareTimer.addEventListener(TimerEvent.TIMER,refreshHardware);
                hardwareTimer.start();
            }
            public function refreshHardware(ev:TimerEvent):void{

                flash.media.scanHardware();
                Alert.show(Camera.names.length.toString());
            }
        ]]>
    </fx:Script>
</s:WindowedApplication>

If I use Camera.names after I unplug any Camera, My app is crashing.

How to solve the issue?

Displume answered 21/10, 2015 at 6:5 Comment(2)
Your code works fine for me in windows 10. Try it in other machines, if it's working so maybe you have some problem in your machine ( AIR version, cam driver, ... ) ...Topminnow
It is working fine on Windows, I have tried that. But it is not working on Mac.Displume
H
2

Actionscript errors should not cause the app to crash. When an app crashes, it usually because it has attempted an illegal operation on the native level like writing to reserved/invalid memory. I would start by looking for a problem with the camera or USB. If you can reproduce the problem using a different brand of webcam, then you can rule out the camera hardware & driver. If you can reproduce the problem on another mac, then it is probably not the USB.

Holman answered 26/10, 2015 at 19:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.