Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading javaFx应用程序中出现了白色屏幕&;它被卡住了_Multithreading_Javafx_Java 8_Java 9_Javacv - Fatal编程技术网

Multithreading javaFx应用程序中出现了白色屏幕&;它被卡住了

Multithreading javaFx应用程序中出现了白色屏幕&;它被卡住了,multithreading,javafx,java-8,java-9,javacv,Multithreading,Javafx,Java 8,Java 9,Javacv,我们正在使用JavaFx和JavaCv开发视频流应用程序, 在将流播放到gridPane(8X8)时,我们偶尔会遇到飞溅的白色屏幕问题,而且这是连续的。 详情:- new Thread(new Runnable() { @Override public void run() { frameGrabber = new FFmpegFrameGrabber(Url); frameGrabb

我们正在使用JavaFx和JavaCv开发视频流应用程序, 在将流播放到gridPane(8X8)时,我们偶尔会遇到飞溅的白色屏幕问题,而且这是连续的。 详情:-

new Thread(new Runnable() {
            @Override
            public void run() {
                frameGrabber = new FFmpegFrameGrabber(Url);
                frameGrabber.setVideoOption("preset","ultrafast");
                frameGrabber.setOption("rtsp_transport","tcp");
                frameGrabber.setOption("stimeout" , "60000");
                frameGrabber.setAudioChannels(0);
                frameGrabber.setAudioCodec(0);
                try {
                   frameGrabber.start();
                    } catch (Exception e) {
                     e.printStackTrace();
                   }
               JavaFXFrameConverter jconverter=new JavaFXFrameConverter();//converting frame to javafx Image

               while(true){
                   try {
               Frame frame = frameGrabber.grab();
                frame.clone();
                if(frame.image!=null){          
                 updateUi(im,jconverter.convert(frame));//im->ImageView
                }
            } catch (FrameGrabber.Exception e) {

                }
            }
                   }
            }
        }).start();


      //updateui explanation

         updateUi(ImageView im,Image image){
                Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    im.setImage(image);//here i m updating imageview
                }
            });
           }
我们在jdk-8中没有得到任何异常,但在jdk-9中我们得到了以下异常。但我不确定这是否与白屏问题有关

Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index -1 out-of-bounds for length 764
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    at java.base/java.util.Objects.checkIndex(Objects.java:372)
    at java.base/java.util.ArrayList.get(ArrayList.java:440)
    at javafx.graphics/javafx.scene.Parent.updateCachedBounds(Parent.java:1723)
    at javafx.graphics/javafx.scene.Parent.recomputeBounds(Parent.java:1667)
    at javafx.graphics/javafx.scene.Parent.doComputeGeomBounds(Parent.java:1520)
    at javafx.graphics/javafx.scene.Parent.access$200(Parent.java:81)
    at javafx.graphics/javafx.scene.Parent$1.doComputeGeomBounds(Parent.java:117)
    at javafx.graphics/com.sun.javafx.scene.ParentHelper.computeGeomBoundsImpl(ParentHelper.java:86)
    at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.superComputeGeomBoundsImpl(RegionHelper.java:78)
    at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.superComputeGeomBounds(RegionHelper.java:62)
    at javafx.graphics/javafx.scene.layout.Region.doComputeGeomBounds(Region.java:3291)
    at javafx.graphics/javafx.scene.layout.Region.access$300(Region.java:149)
    at javafx.graphics/javafx.scene.layout.Region$1.doComputeGeomBounds(Region.java:170)
    at javafx.graphics/com.sun.javafx.scene.layout.RegionHelper.computeGeomBoundsImpl(RegionHelper.java:89)
    at javafx.graphics/com.sun.javafx.scene.NodeHelper.computeGeomBounds(NodeHelper.java:117)
    at javafx.graphics/javafx.scene.Node.updateGeomBounds(Node.java:3831)
    at javafx.graphics/javafx.scene.Node.getGeomBounds(Node.java:3793)
    at javafx.graphics/javafx.scene.Node.getLocalBounds(Node.java:3741)
    at javafx.graphics/javafx.scene.Node.updateTxBounds(Node.java:3895)
    at javafx.graphics/javafx.scene.Node.getTransformedBounds(Node.java:3687)
    at javafx.graphics/javafx.scene.Node.updateBounds(Node.java:766)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1851)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1849)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1849)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1849)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1849)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1849)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1849)
    at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1849)
    at javafx.graphics/javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2522)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:410)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:409)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:436)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:518)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:498)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:491)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:319)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
    at java.base/java.lang.Thread.run(Thread.java:844)

类似的异常通常是线程问题的症状(即,以某种方式从后台线程访问场景图)。我在这里看不到任何明显的东西(但我不知道您使用的frame grabber API)。framegrabber仅用于从url抓取图像。另外:永远不要挤压异常。如果出现问题,至少应该记录一个异常。您可能应该让
try
-
catch
围绕循环,而不是在循环内部。您需要从javafx应用程序线程对UI进行更新。为此,请在
updateUi
中使用
Platform.runLater
。我只在javafx应用程序线程内更新imageview。但我仍然遇到同样的问题。