"缓冲区尚未创建" ......而创建缓冲区 [英] "Buffers have not been created" ... whilst creating buffers
问题描述
我有(我认为是)一个JFrame的一个简单的BufferStrategy中。它是像这样创建:
//缓冲区
container.createBufferStrategy(2);
策略= container.getBufferStrategy();
不过,偶尔我收到以下错误(它指向preceeding片段作为违规项目的第一行):
的 java.lang.IllegalStateException:没有创建缓冲区的
此错误是特殊的,因为它来得快,去 - 有时它被触发时,有时没有。我的犯罪嫌疑人的,这意味着它是一个线程问题。没有任何人有任何指针,以什么可能会在这里吗?我有点茫然,因为我已经尝试做Java的说什么要我做的!
编辑:全跟踪:
异常线程mainjava.lang.IllegalStateException:缓冲区没有创建
在sun.awt.windows.WComponentPeer.getBackBuffer(WComponentPeer.java:877)
在java.awt.Component中$ FlipBufferStrategy.getBackBuffer(Component.java:3815)
在java.awt.Component中$ FlipBufferStrategy.updateInternalBuffers(Component.java:3800)
在java.awt.Component中$ FlipBufferStrategy.createBuffers(Component.java:3791)
在java.awt.Component中$ FlipBufferStrategy<&初始化GT;(Component.java:3730)
在java.awt.Component中$ FlipSubRegionBufferStrategy<&初始化GT;(Component.java:4253)
在java.awt.Component.createBufferStrategy(Component.java:3612)
在java.awt.Window.createBufferStrategy(Window.java:3015)
在java.awt.Component.createBufferStrategy(Component.java:3536)
在java.awt.Window.createBufferStrategy(Window.java:2990)
帧需要打电话时要显示的 createBufferStrategy
。另外,作为camickr指出,你需要从EDT调用它。
要确保这一点的方法之一是延长的JFrame
和覆盖信息addNotify
:
类MyFrame扩展的JFrame {
公共无效信息addNotify(){
super.addNotify();
// 缓冲
createBufferStrategy(2);
策略= getBufferStrategy();
}
}
I have (what I thought was) a straightforward BufferStrategy for a JFrame. It is created like so:
// Buffer
container.createBufferStrategy(2);
strategy = container.getBufferStrategy();
However, occassionally I receive the following error (which points to the first line of the preceeding snippet as the offending item) :
java.lang.IllegalStateException: Buffers have not been created
This error is peculiar as it comes and goes - sometimes it is triggered, sometimes not. I suspect this means it's a threading issue. Does anyone have any pointers as to what might be going on here? I'm a little at a loss, since I'm already trying to do what Java says it wants me to do!
edit: full trace:
Exception in thread "main" java.lang.IllegalStateException: Buffers have not been created
at sun.awt.windows.WComponentPeer.getBackBuffer(WComponentPeer.java:877)
at java.awt.Component$FlipBufferStrategy.getBackBuffer(Component.java:3815)
at java.awt.Component$FlipBufferStrategy.updateInternalBuffers(Component.java:3800)
at java.awt.Component$FlipBufferStrategy.createBuffers(Component.java:3791)
at java.awt.Component$FlipBufferStrategy.<init>(Component.java:3730)
at java.awt.Component$FlipSubRegionBufferStrategy.<init>(Component.java:4253)
at java.awt.Component.createBufferStrategy(Component.java:3612)
at java.awt.Window.createBufferStrategy(Window.java:3015)
at java.awt.Component.createBufferStrategy(Component.java:3536)
at java.awt.Window.createBufferStrategy(Window.java:2990)
The frame needs to be displayable when you call createBufferStrategy
. Also as camickr has pointed out you need to call it from the EDT.
One way to ensure this is to extend JFrame
and override addNotify
:
class MyFrame extends JFrame {
public void addNotify() {
super.addNotify();
// Buffer
createBufferStrategy(2);
strategy = getBufferStrategy();
}
}
这篇关于&QUOT;缓冲区尚未创建&QUOT; ......而创建缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!