处理createGraphics在setup方法之外失败

时间:2014-12-06 06:18:39

标签: java processing pgraphics

这是我正在使用的代码的链接。 https://github.com/positlabs/lpl-processor/blob/master/lpl_processor/lpl_processor.pde

问题在于我想推断电影尺寸,但我需要等到电影的第一帧被读取。当我尝试在createGraphics()以外的任何地方拨打setup()时,它会失败。

这是一个精简的测试用例。

    import processing.video.*;

    Movie movie;
    PGraphics graphics;

    void setup() 
    {
      size(800, 600);

      movie = new Movie(this, "sparkle.mov");
      movie.play();

      graphics = createGraphics(800, 600); // succeess graphic!
    }

    void movieEvent(Movie m) {
      m.read();
      graphics = createGraphics(m.width, m.height); // failure grahic!!
    }


And here is the stack trace.



`
java.lang.NullPointerException
    at processing.core.PApplet.makeGraphics(PApplet.java:1916)
    at processing.core.PApplet.createGraphics(PApplet.java:1872)
    at processing.core.PApplet.createGraphics(PApplet.java:1791)
    at sketch_141206a.movieEvent(sketch_141206a.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at processing.video.Movie.fireMovieEvent(Unknown Source)
    at processing.video.Movie.invokeEvent(Unknown Source)
    at processing.video.Movie$2.rgbFrame(Unknown Source)
    at org.gstreamer.elements.RGBDataAppSink$AppSinkNewBufferListener.newBuffer(RGBDataAppSink.java:162)
    at org.gstreamer.elements.AppSink$2.callback(AppSink.java:184)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:455)
    at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:485)
error, disabling movieEvent() for sparkle.mov
`

1 个答案:

答案 0 :(得分:0)

执行此操作的正确方法是draw函数,但它使初始化有点时髦。