Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swing + Cocoa = BOOM (solved)



Problem solved (no thanks to you guys!).

The solution is to allocate Cocoa data structures on the AppKit thread, exclusively, if they need to be deallocated later. More specifically, since our PDF data is generated on the Java/Swing thread, we put it in a normal Java byte array, and pass that to the AppKit thread using JNI. The AppKit thread allocates its own NSData, copies the PDF data into it, then signals the Swing thread that its copy of the data is no longer needed. And the AppKit thread releases its own data later.

So we have a duplicated data structure that serves no other purpose than to prevent the JVM from crashing.

Is this a JVM bug? An AppKit bug? Has anybody else out there had trouble allocating Cocoa data in the Swing thread and deallocating in the AppKit thread?

Geoff

On 25 Mar 2005, at 12:26, Geoff Levner wrote:

Greetings!

We have a Swing application that uses an AWT CocoaComponent to display PDF files.

More specifically, the Java/Swing thread generates the PDF and creates an NSPDFImageRep, which is transmitted to the AppKit thread via the CocoaComponent's sendMessage method. The AppKit thread receives the NSPDFImageRep and displays it in the NSView. And in the Swing thread, I am careful never to touch the NSPDFImageRep once it has been passed to the AppKit thread.

Usually this works fine. But occasionally the JVM crashes, apparently when the AppKit thread releases the old NSPDFImageRep.

Is there something fundamentally wrong with this approach, or is this a bug? If anybody can suggest a better way to do this, I would appreciate it...

Thanks in advance,
Geoff

_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Swing + Cocoa = BOOM (From: Geoff Levner <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.