5 Replies Latest reply: Sep 22, 2007 2:24 AM by (ewoutnwn) RSS

    Error using MouseEventHandler

      Hello,

      There occurs an error when I register a MouseEventHandler with the following code(this code is executed always when the pdf-document is being opened):

      function initialize()
      {
      var a3d = getAnnots3D(0)[0];
      if ( a3d.activated )
      {
      context3D = a3d.context3D;

      //Removes possible previous added MouseEventHandler
      var handler = context3D.runtime.getEventHandler(0);
      if(handler != null)
      context3D.runtime.removeEventHandler(handler);

      //Adds eventhandler
      var meh = new context3D.MouseEventHandler();
      meh.reportAllTargets = true;
      meh.onMouseUp = true;
      meh.onEvent = function(mouseEvent)
      {
      if(mouseEvent.isMouseUp)
      {
      try
      {
      var hits = mouseEvent.hits;
      clickedNode = hits.shift().target;
      var scene = context3D.scene;
      var clickedMesh = scene.meshes.getByName(clickedNode.name);

      if(vorigeNode != null)
      {
      var vorigeMesh = scene.meshes.getByName(vorigeNode.name);
      vorigeMesh.renderMode = "solid";
      }
      vorigeNode = clickedNode;

      clickedMesh.renderMode = "shaded illustration";
      }
      catch(err)
      {
      console.println(err);
      }
      }
      }
      context3D.runtime.addEventHandler(meh);
      }

      The error occurs at closing the pdf-file. The error-message is: "An unhandled win32 exeption occurred in Acrobat.exe[5068]. On another computer I also got an error like "The read or write operation on the memory failed.

      Can someone help me and explain the cause and solution for this error?

      Thanks in advance,

      ewout
        • 1. Re: Error using MouseEventHandler
          ewout,
          I notice three things:

          1) you're missing a closing brace at line 7.
          2) It doesn't look like you're ever calling the function:
          initialize();

          3) If both of the above are just typo's, try adding a delay at the beginning of your script. It's probably that the 3D annot is not yet loaded when you're trying to access it.

          Good luck!
          • 2. Re: Error using MouseEventHandler
            Community Member
            Hi gary,

            thanks for your reply.

            At point 1: Thanks for your comment, but that doesn't solve the problem. I think I forgot the brace while copying some part of the code, because Acrobat doesn't allow you to forget something like that ;).

            At point 2: the function initialize is fired whenever the pdf-file has been opened in adobe reader >= 8.0 or acrobat 8.0 and intialized again after changing the code in acrobat 8.0.

            At point 3: Sorry, I forgot to tell that there is also some delay at the start of this script [ timeout = app.setInterval( "initialize()", 1000 ); ] and the MouseEventHandler is only added if a3d.activated == true!

            To prevent questions about the code I didn't copy above I will give you all code of function initialize()

            //======================Function initialize()===================
            timeout = app.setInterval( "initialize()", 1000 );
            timeout.count = 0;
            var waitingFor3DActivated = true;
            var vorigeNode;

            function initialize()
            {
            if (app.formsVersion >= 8.0)
            {
            app.fs.cursor = cursor.visible;
            app.fs.isFullScreen = true;
            console.println( " " );
            console.println( "checking to see if the 3D Annotation has been activated yet..." );

            if ( waitingFor3DActivated )
            {
            var a3d = getAnnots3D(0)[0];
            if ( a3d.activated )
            {
            context3D = a3d.context3D;

            //Removes possible previous added MouseEventHandler
            var handler = context3D.runtime.getEventHandler(0);
            if(handler != null)
            context3D.runtime.removeEventHandler(handler);

            //Adds eventhandler
            var meh = new context3D.MouseEventHandler();
            meh.reportAllTargets = true;
            meh.onMouseUp = true;
            meh.onEvent = function(mouseEvent)
            {
            if(mouseEvent.isMouseUp)
            {
            try
            {
            var hits = mouseEvent.hits;
            clickedNode = hits.shift().target;
            var scene = context3D.scene;
            var clickedMesh = scene.meshes.getByName(clickedNode.name);

            if(vorigeNode != null)
            {
            var vorigeMesh = scene.meshes.getByName(vorigeNode.name);
            vorigeMesh.renderMode = "solid";
            }
            vorigeNode = clickedNode;

            clickedMesh.renderMode = "shaded illustration";
            goItris(1, clickedNode.name); //fires app.launchURL(...)
            }
            catch(err)
            {
            console.println(err);
            }
            }
            }
            context3D.runtime.addEventHandler(meh);
            //eventhandler added above
            //Nothing wrong with the 4 methods below!
            setModel(context3D);
            countNodes("*Model_Space");
            setButtons();
            setTools();
            }
            //a3d.activated==false

            if ( timeout.count >= 10 ) // seconds
            {
            console.println( "I'm giving up - the 3D Annotation is still not activated" );
            app.clearInterval( timeout );
            }
            timeout.count++;
            }
            }
            else //formVersion < 8.0
            {
            var nButton = app.alert({ cMsg: "Uw huidige versie van Acrobat Reader ondersteund geen 3D functionaliteit. Wilt u het venster sluiten?" , cTitle: " Versie Check", nIcon: 2, nType: 1 });
            //if ( nButton == 4 ) this.closeDoc();
            }

            }
            //===================end funtion initialize()==================

            However, everything with the MouseEventHandler works fine until closing the pdf-file. Then I get the errors described above. Besides, everything else worked fine at closing the document until I added the MouseEventHandler. So I assume, that's the problem.

            So perhaps, there's wrong something else?!

            thanks in advance,

            ewout
            • 3. Re: Error using MouseEventHandler
              Community Member
              Hi gary and others,

              after further testing I found out that Adobe crashes(!) always when there has been added an eventhandler to the runtime of the context3D (or 3d-engine). But it only crashes when the event has been fired, not when the pdf-file has been closed without firing the event!

              The eventhandler will be added in DocumentLevel at the Open-event. The used code has been added in previous posts on this topic.

              The error occurs at closing a pdf-file with a 3d-model after an eventhandler has been added and the corresponding event has been fired.

              The error-message is: "An unhandled win32 exeption occurred in Acrobat.exe[5068]" or "An unhandled win32 exeption occurred in Acrobat.exe[3068]". On another computer I also got an error like "The read or write operation on the memory failed. Adobe crashes using Acrobat or the Reader.

              Anybody knows what to do to solve this problem?

              regards,

              ewout
              • 4. Re: Error using MouseEventHandler
                ewout,
                I have a solution for you that works. But first, using you're approach I do indeed encounter crashes, though not every time. I worked with your script for quite a while, and also made more simplistic versions for MouseEventHandlers and RenderEventHandlers. Again, I get crashes, but it's intermittent and I haven't yet determined the exact cause.

                Here's the solution (simple code example below). The only needed change is that the function is now in a script attached to the 3D annot, and then that function is called from your page button. When I create eventHandlers, I typically create them in Javascripts attached to the 3D annot itself. This is the more efficient (in processing) method. If you would like a button on a page to create a handler(as in your example), put the function in a script attached to the 3D annot, and then call the function from the page. This works dependably with no errors at all. I have many many documents which use this approach successfully. The code below shows the 3D annot script at top and the page button script at bottom.

                //======= attach to 3D annot ========
                function initializeMEH()
                {
                myMEH = new MouseEventHandler();
                myMEH.onEvent = function(event)
                {
                console.println("=================");
                console.println("mouseX = " + event.mouseX );
                console.println("mouseY = " + event.mouseY );
                }
                runtime.addEventHandler(myMEH);
                }

                //======= attach to Page button =======
                var a3d = getAnnots3D(0)[0].context3D;
                a3d.initializeMEH();
                • 5. Re: Error using MouseEventHandler
                  Community Member
                  hi gary,

                  thanks a lot! This solves the problem. Thank you for your time to help me.

                  regards,

                  ewout