Search code examples
actionscript-3debuggingcrashmeshvertex

How to detect Adobe Flash crash reason?


Edit02: The reason why the flash crash because the wrong distance cause the programm to divide something by 0 - well I found the error on my own, but my question still is, is there something like a crashreport that you can add / edit?

Edit: I found the bug in the script its located here

          if(baseVerticies[vertX]-boneObj.x < 0){
                distance = distance*-1;
            }

at one point it generates the wrong distance, but this is not what the program causes to crash, I know how to solve the bug but it would still be interesting how to add functions to detect flash crash reasons

OLD: Hey I am currently testing the CS6 Flash demo but one function always kills flash and I dont get any error messages, so my question is ... how can I hunt the bug down?

The only things I know: it crashes when I call a certain function (the one which I posted below) - it doesnt crash on the first call ... more like on the third or second

is there any way to add debugEvents or something als that would be usefull to track the error?

thx in advance =)

public function rotateBone(boneObj : Bone, point : Point){
            //rotates the boneGrafik
            boneObj.rotation = (point.x+boneObj.old_rotation)/2;

            if(axis == "horizontal"){
                var firstV : int = selected_bone*(squares+1)*2;
                var lastV : int = selected_bone*(squares+1)*2 + squares*2;
                var radius : Number = Math.sqrt((verticies[lastV]-verticies[firstV])*(verticies[lastV]-verticies[firstV])+
                    (verticies[lastV+1]-verticies[firstV+1])*(verticies[lastV+1]-verticies[firstV+1]));

                //will be exectued for every single vertex
                for(var s = 0; s<=squares; s++){
                    var vertX : int = selected_bone * (squares+1) * 2 + s*2;

                    var distance : Number = Math.sqrt((verticies[vertX]-boneObj.x)*(verticies[vertX]-boneObj.x)+
                        (verticies[vertX+1]-boneObj.y)*(verticies[vertX+1]-boneObj.y));

                    //calculates Vector
                    var rads:Number = boneObj.rotation / 180 * Math.PI;
                    var p:Point = new Point();
                    p.x=Math.cos(rads);
                    p.y=Math.sin(rads);

                    //baseMesh is used in order to check if the vertex pos is positiv / negative
                    if(baseVerticies[vertX]-boneObj.x < 0){
                        distance = distance*-1;
                    }

                    verticies[vertX] =  boneObj.x +  p.x * radius * (distance/radius);
                    verticies[vertX+1] =  boneObj.y +  p.y * radius * (distance/radius);

                }
            }else if (axis == "vertical"){
                for(var r = 0; r<=rows; r++){
                    vertX = r * (squares+1) * 2 + selected_bone * 2;

                }
            }
            updateMesh();
        }

Solution

  • I'm not sure what you mean it crashes without exception. Are you testing in the browser? If so, then you could download and install the appropriate Flash debugger player from the list here: http://www.adobe.com/support/flashplayer/downloads.html

    This should give you an error window whenever FlashPlayer crashes, which will contain debugging information. It will also write crashes and debugging data to a log file. There's more info on that here: http://helpx.adobe.com/flash-player/kb/configure-debugger-version-flash-player.html

    Finally, if you want to catch and handle otherwise unhandled exceptions, you can do that in FP10.1 and later. Here are the Adobe docs about it: http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/events/UncaughtErrorEvent.html, and here is the sample code from that page:

    package
    {
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.ErrorEvent;
    import flash.events.UncaughtErrorEvent;
    import flash.net.URLRequest;
    
    public class LoaderUncaughtErrorEventExample extends Sprite
    {
        private var ldr:Loader;
    
        public function LoaderUncaughtErrorEventExample()
        {
            ldr = new Loader();
            ldr.load(new URLRequest("child.swf"));
            ldr.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
        }
    
        private function uncaughtErrorHandler(event:UncaughtErrorEvent):void
        {
            if (event.error is Error)
            {
                var error:Error = event.error as Error;
                // do something with the error
            }
            else if (event.error is ErrorEvent)
            {
                var errorEvent:ErrorEvent = event.error as ErrorEvent;
                // do something with the error
            }
            else
            {
                // a non-Error, non-ErrorEvent type was thrown and uncaught
            }
        }
    }
    }