processing-video icon indicating copy to clipboard operation
processing-video copied to clipboard

GstBus infinite threads can lead to crash

Open sebastian-meier opened this issue 1 year ago • 0 comments

For every new Movie there is a GstBus - Thread being generated. If a Movie is properly disposed after a short playing time and a new Movie is created the old bus is being used (as far as I can tell).

movie.pause();
movie.stop();
movie.dispose();
movie = null;
System.gc();

movie = new Movie...

However if a Movie is playing for longer than a few minutes the thread is not being reused but a new one is created. Over time this can lead to many GstBus Threads which can slow down and even crash the application.

The threads can be checked with VisualVM.

Is there any way to avoid this?

Example (simply change the counter limit to something <= 750):

import processing.video.*;

Movie mov;

void settings() {
  size(800, 600);
}

void setup() {
  mov = new Movie(this, "test1.mp4");
  mov.play();
}

void draw() {
  background(255);

  if (mov != null) {
    try {
      image(mov, 0, 0);
    } catch(ArrayIndexOutOfBoundsException exception) {
       println("not ready");
    }
  }
  counter += 1;
  if (counter > 1000) {
    counter = 0;
    thread("mousePressed");
  }
}

int counter = 0;

void mousePressed() {
  String[] videos = {"test1.mp4", "test2.mp4", "test3.mp4"};
  int vidId = round(random(-0.45, 2.5));
  println(videos[vidId]);
  
  mov.pause();
  mov.stop();
  mov.dispose();
  mov = null;
  System.gc();
  
  mov = new Movie(this, videos[vidId]);
  mov.play();
  
}

void movieEvent(Movie m) {
  if (m.available()) {
     m.read();
  }
}

sebastian-meier avatar May 12 '23 07:05 sebastian-meier