Apple AWT内部异常:NSWindow拖动区域应仅在主线程上失效

huangapple go评论69阅读模式
英文:

Apple AWT Internal Exception: NSWindow drag regions should only be invalidated on the Main Thread

问题

以下是要翻译的内容:

我正在尝试运行一个 PApplet 类。我在 MacOS 上的 Eclipse 上运行它。所有必要的库文件都包含在应用程序中,并且使用 Java 1.8 来编译和运行这个类。
MacOS 版本是 Catalina,10.15.6 (19G2021)。我得到了以下错误:

2020-10-13 13:23:51.528 java[20420:1238853] Apple AWT Internal Exception: NSWindow drag regions should only be invalidated on the Main Thread!
2020-10-13 13:23:51.528 java[20420:1238853] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
0   CoreFoundation                      0x00007fff338dbb57 __exceptionPreprocess + 250
1   libobjc.A.dylib                     0x00007fff6c7245bf objc_exception_throw + 48
2   CoreFoundation                      0x00007fff3390434c -[NSException raise] + 9
3   AppKit                              0x00007fff30afe5ec -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 310
4   AppKit                              0x00007fff30ae6052 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1416
5   AppKit                              0x00007fff30ae5ac3 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
6   libnativewindow_macosx.jnilib       0x000000015e4d8f9e Java_jogamp_nativewindow_macosx_OSXUtil_CreateNSWindow0 + 398
7   ???                                 0x0000000112dad407 0x0 + 4611298311
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我编写的参考代码如下:

package module1;
import processing.core.PApplet;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.geo.Location;
import de.fhpotsdam.unfolding.providers.AbstractMapProvider;
import de.fhpotsdam.unfolding.providers.Google;
import de.fhpotsdam.unfolding.providers.MBTilesMapProvider;
import de.fhpotsdam.unfolding.utils.MapUtils;

public class HelloWorld extends PApplet
{
    // ...(代码内容较多,此处省略)
}
英文:

I am trying to run a PApplet class. I am running it on Eclipse, in MacOS. All the necessary Library files are included in the application and using Java 1.8 to compile and run the class.
Mac OS Version is Catalina, 10.15.6 (19G2021). I am getting the following error:

	2020-10-13 13:23:51.528 java[20420:1238853] Apple AWT Internal Exception: NSWindow drag regions should only be invalidated on the Main Thread!
	2020-10-13 13:23:51.528 java[20420:1238853] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
	*** First throw call stack:
	(
	0   CoreFoundation                      0x00007fff338dbb57 __exceptionPreprocess + 250
	1   libobjc.A.dylib                     0x00007fff6c7245bf objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff3390434c -[NSException raise] + 9
	3   AppKit                              0x00007fff30afe5ec -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 310
	4   AppKit                              0x00007fff30ae6052 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1416
	5   AppKit                              0x00007fff30ae5ac3 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
	6   libnativewindow_macosx.jnilib       0x000000015e4d8f9e Java_jogamp_nativewindow_macosx_OSXUtil_CreateNSWindow0 + 398
	7   ???                                 0x0000000112dad407 0x0 + 4611298311
	)
	libc++abi.dylib: terminating with uncaught exception of type NSException

Reference Code that I have written.

package module1;
import processing.core.PApplet;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.geo.Location;
import de.fhpotsdam.unfolding.providers.AbstractMapProvider;
import de.fhpotsdam.unfolding.providers.Google;
import de.fhpotsdam.unfolding.providers.MBTilesMapProvider;
import de.fhpotsdam.unfolding.utils.MapUtils;


	public class HelloWorld extends PApplet
	{
		/** Your goal: add code to display second map, zoom in, and customize the background.
		 * Feel free to copy and use this code, adding to it, modifying it, etc.  
		 * Don't forget the import lines above. */
	
		// You can ignore this.  It's to keep eclipse from reporting a warning
		private static final long serialVersionUID = 1L;
	
		/** This is where to find the local tiles, for working without an Internet connection */
		public static String mbTilesString = "blankLight-1-3.mbtiles";
		
		// IF YOU ARE WORKING OFFLINE: Change the value of this variable to true
		private static final boolean offline = false;
		
		/** The map we use to display our home town: La Jolla, CA */
		UnfoldingMap map1;
		
		/** The map you will use to display your home town */ 
		UnfoldingMap map2;
	
		public void setup() {
			size(800, 600, P2D);  // Set up the Applet window to be 800x600
			                      // The OPENGL argument indicates to use the 
			                      // Processing library's 2D drawing
			                      // You'll learn more about processing in Module 3
	
			// This sets the background color for the Applet.  
			// Play around with these numbers and see what happens!
			this.background(200, 200, 200);
			
			// Select a map provider
			AbstractMapProvider provider = new Google.GoogleTerrainProvider();
			// Set a zoom level
			int zoomLevel = 10;
			
			if (offline) {
				// If you are working offline, you need to use this provider 
				// to work with the maps that are local on your computer.  
				provider = new MBTilesMapProvider(mbTilesString);
				// 3 is the maximum zoom level for working offline
				zoomLevel = 3;
			}
			
			// Create a new UnfoldingMap to be displayed in this window.  
			// The 2nd-5th arguments give the map's x, y, width and height
			// When you create your map we want you to play around with these 
			// arguments to get your second map in the right place.
			// The 6th argument specifies the map provider.  
			// There are several providers built-in.
			// Note if you are working offline you must use the MBTilesMapProvider
			map1 = new UnfoldingMap(this, 50, 50, 350, 500, provider);
			map2 = new UnfoldingMap(this, 450, 450, 350, 500, provider);
	
			// The next line zooms in and centers the map at 
		    // 32.9 (latitude) and -117.2 (longitude)
		    map1.zoomAndPanTo(zoomLevel, new Location(32.9f, -117.2f));
			map2.zoomAndPanTo(zoomLevel, new Location(32.9f, -117.2f));
			
			// This line makes the map interactive
			MapUtils.createDefaultEventDispatcher(this, map1);
			MapUtils.createDefaultEventDispatcher(this, map2);
			
			// TODO: Add code here that creates map2 
			// Then you'll modify draw() below
	
		}
	
		/** Draw the Applet window.  */
		public void draw() {
			// So far we only draw map1...
			// TODO: Add code so that both maps are displayed
			map1.draw();
			map2.draw();
		}
	
		
	}

答案1

得分: 4

我对你没有一个完整的答案,但我想我有一个解决方法,同时可能也已经缩小了范围(假设你的问题与我的相同,它肯定呈现相同的问题)... 我认为这与使用旧版本的JOGL有关,我在JOGL 2.1.5左右的版本中看到了这个问题。由于存在更新版本的JOGL,这个问题可能仍未解决。不过,我目前还不能测试这个理论,希望我能够尽早有机会做到这一点。

解决方法

就我所知,问题似乎首次出现在JDK8u252+和JDK11.0.7+的版本中。如果我使用JDK8u242或JDK11.0.6,那么问题就不再出现。

调查

基于我首次发现问题的版本,似乎与2020年1月至2020年4月期间的一次提交有关,可能是这个提交:在OpenJDK项目中的4f1fabd8d08581bc9e0c4b3cc7dffb7f7cc0d5c8。然而,话虽如此,请对这个特定提交的指向持怀疑态度,因为它基本上只是在正确的时间范围内进行的编辑(我想是这样),涉及到了似乎与相关代码有关的部分。我之所以提到它,只是希望能帮助那些在这个领域有更多知识的人缩小问题的范围。

英文:

I don't have a full answer for you, but I think I have a work-around as well as might have narrowed it down (assuming your issue is the same as mine, it certainly presents the same)... I think that it is related to use of old JOGL versions, I'm seeing it with JOGL 2.1.5ish. Presumably this remains unresolved due to the existence of newer versions of JOGL. I can't test this theory yet, though, hopefully I'll get a chance to do that sooner than later.

Workaround

As far as I can, the problem first started appearing with version JDK8u252+ and JDK11.0.7+. If I use JDK8u242 or JDK11.0.6 then I no longer see the issue.

Investigation

Based on the versions where I first see problems, It appears to be related to a commit in the Jan 2020 to April 2020 timeframe, possibly this commit: 4f1fabd8d08581bc9e0c4b3cc7dffb7f7cc0d5c8 in the OpenJDK project. However, with that said, take the pointer to this specific commit with a huge grain of salt, because it's basically just an edit in the right timeframe (I think) that touches what appears to be related code. I only mention it in case it might help someone with more knowledge in the area narrow down the problem.

答案2

得分: 1

你必须使用jdk8u242-b08版本的jre。
从这里下载

英文:

You have to use jdk8u242-b08 for jre.
download from here

答案3

得分: 0

我遇到了同样的问题。只需使用较早版本的Java 8(JDK 8u202),并将Eclipse编译器设置为1.8级别,然后您就应该能够摆脱这个错误。

英文:

I faced the same problem.Just use an earlier version of java8 (JDK 8u202) and set the eclipse compiler to level 1.8 and then you should be able to get rid of the error.

答案4

得分: -1

尝试在public void setup()中删除OPENGL参数P2D:

size(800, 600);
英文:

try to remove the OPENGL argument P2D in public void setup() {
size(800, 600, P2D);

huangapple
  • 本文由 发表于 2020年10月13日 16:48:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/64331790.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定