5 messages in net.java.dev.jna.usersRe: [jna-users] Callback repeatedly c...
FromSent OnAttachments
Paul GiffordSep 12, 2008 7:48 am 
Timothy WallSep 12, 2008 8:14 am 
Paul GiffordSep 12, 2008 8:46 am 
Timothy WallSep 12, 2008 8:50 am 
Paul GiffordSep 12, 2008 9:27 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Callback repeatedly calledActions...
From:Timothy Wall (twal@dev.java.net)
Date:Sep 12, 2008 8:14:57 am
List:net.java.dev.jna.users

On Sep 12, 2008, at 10:49 AM, Paul Gifford wrote:

Hi,

I've got my callback installed and it seems to be working, except it gets called repeatedly. I've duplicated C++ code that uses callbacks - C++ Builder and Visual C++ samples that work fine. Is it possible I've done something wrong with JNA to cause this?

In my callback I have a couple of system.outs and after a while I get this exception:

java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) at sun .reflect .DelegatingMethodAccessorImpl .invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.jna.CallbackReference $DefaultCallbackProxy.callback_inner(CallbackReference.java:274) at com.sun.jna.CallbackReference $DefaultCallbackProxy.callback(CallbackReference.java:296) Caused by: java.lang.StackOverflowError at sun.nio.cs.SingleByteEncoder.encodeArrayLoop(SingleByteEncoder.java: 91) at sun.nio.cs.SingleByteEncoder.encodeLoop(SingleByteEncoder.java:130) at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:544) at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:252) at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:106) at java.io.OutputStreamWriter.write(OutputStreamWriter.java: 190) at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:111) at java.io.PrintStream.newLine(PrintStream.java:495) at java.io.PrintStream.println(PrintStream.java:757) at footietest.RunMe$4.callback(RunMe.java:210) ... 5 more

If I remove the system.outs, when I close the application I get this message:

JNA: uncaught exception in callback, continuing

Any ideas on what I might be doing wrong?

Your callback is overflowing the stack with whatever it is sending to PrintStream.println.

The callback_inner stuff is a wrapper around your callback code to catch exceptions that you don't catch.

Your callback apparently doesn't return until you close the application. Is that expected? Do you catch any exceptions which might be thrown by your callback? What's your callback method signature?