We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › segfaults and mem leaks in Movie, processing.video
Page Index Toggle Pages: 1
segfaults and mem leaks in Movie, processing.video (Read 1343 times)
segfaults and mem leaks in Movie, processing.video
Dec 11th, 2009, 1:05am
 

Hi, I am working with the Movie library and import processing.video.*.

My program is pretty simple (~100 lines). It does nothing but read a bunch of video files and display them. But it invariably leaks memory and eventually segfaults or throws an exception. I have read the known problems doc, but did not find anything. I am running Processing 1.0.9 on MacOSX version 10.5.8. I've sprinkled System.gc() in various logical places, but that doesn't make a difference.

Here are the errors I see:

Either:

Invalid memory access of location 0xffffffff eip=0x9677c57f

Or:

Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException
     at java.lang.System.arraycopy(Native Method)
     at processing.core.PGraphics2D.simple_image(PGraphics2D.java:1487)
     at processing.core.PGraphics2D.imageImpl(PGraphics2D.java:1407)
     at processing.core.PGraphics.image(PGraphics.java:2221)
     at processing.core.PGraphics.image(PGraphics.java:2197)
     at processing.core.PApplet.image(PApplet.java:7286)
     at sketch_dec11a.draw(sketch_dec11a.java:68)
     at processing.core.PApplet.handleDraw(PApplet.java:1425)
     at processing.core.PApplet.run(PApplet.java:1327)
     at java.lang.Thread.run(Thread.java:613)
java(11115,0xa08d2720) malloc: *** error for object 0x77a1fe80: double free
*** set a breakpoint in malloc_error_break to debug

Here is the program:

import processing.video.*;
import java.util.Vector;

// a very simple sketch that leaks memory all over the place,
// eventually segfaulting or throwing an exception.
int tileWidth = 640;
int tileHeight = 480;
Movie movie;
int numFiles = 0;
int[] order;
int curMovie = 0;
Vector fileNames = new Vector();

void setup() {
 // list all the files and pick those ending in .AVI
 File[] allFiles = new
     File("/Users/stein/Documents/Processing/summer05/Clips/").listFiles();
 for (int i = 0; i < allFiles.length; i++) {
   String movieFileName = allFiles[i].getAbsolutePath();
   if (movieFileName.endsWith(".AVI")) {
     fileNames.add(movieFileName);
   }
 }
 size(tileWidth, tileHeight, P2D);
 // load the movie into the slot
 int movieNum = (curMovie ++) % fileNames.size();
 String movieFileName = fileNames.get(movieNum).toString();
 print("loading " + movieFileName + "\n");
 movie = new Movie(this, movieFileName);
 movie.play();
 movie.speed(16.0);
}

void draw() {
 if (movie.duration() == movie.time()) {
   // done. load a new movie
   movie.stop();
   movie = null;
   System.gc();
   int movieNum = (curMovie ++) % fileNames.size();
   String movieFileName = fileNames.get(movieNum).toString();
   movie = new Movie(this, movieFileName);
   movie.play();
   movie.speed(16.0);
 }
 image(movie, 0, 0, tileWidth, tileHeight);
 System.gc();
}

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

Re: segfaults and mem leaks in Movie, processing.video
Reply #1 - Dec 11th, 2009, 6:00am
 
the out of bounds exception looks like it could be this line

  int movieNum = (curMovie ++) % fileNames.size();
  String movieFileName = fileNames.get(movieNum).toString();

try printing movieNum in the middle there and make sure it's a valid fileName.

it says line 68 but your code is only 50 odd lines long. am guessing that's due to all the extra bits the IDE adds during export.
Re: segfaults and mem leaks in Movie, processing.video
Reply #2 - Dec 12th, 2009, 9:27pm
 
That is not it. I put a try-catch around that and the exception is not there.

Anyways, the exception is just a symptom of the memory leak.

Memory just grows and grows until the system breaks in some way. Here is another way it breaks (at this point it's using about 2.4GB of VM):

Exception
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

in thread "Thread-311" java.lang.OutOfMemoryError: requested 307200 bytes for jint in /SourceCache/HotSpot15/HotSpot15-141/src/share/vm/prims/jni.cpp. Out of swap space?
Re: segfaults and mem leaks in Movie, processing.video
Reply #3 - Dec 12th, 2009, 9:45pm
 

I've simplified the above code that triggers the memory leak. It still leaks until it eventually seg faults or throws an exception. Here is the simplified code:

import processing.video.*;

Movie movie;
String movieFileName =
 "/Users/stein/Documents/Processing/summer05/Clips/MVI_1626.AVI";

void setup() {
 size(320, 240, P2D);
 movie = new Movie(this, movieFileName);
 movie.play();
}

void draw() {
 if (movie.duration() == movie.time()) {
   movie.stop();
   movie = new Movie(this, movieFileName);
   movie.play();
 }
 image(movie, 0, 0);
}

void movieEvent(Movie m) {
 m.read();
}
Re: segfaults and mem leaks in Movie, processing.video
Reply #4 - Dec 12th, 2009, 9:47pm
 
I've done various things like sprinkling System.gc() throughout the code, and explicitly setting the movie to null before re-initializing it.
Page Index Toggle Pages: 1