Error while loading new videos into ofVideoPlayer

I am trying to load new videos to an instance of ofVideoPlayer. working on the latest version from GitHub. but got the below error message by loading new video at the 2nd time or 3rd time. I called ‘stop()’ and ‘closeVideo()’ methods before loading new video. Do you have any idea?

ofQuickTimePlayer.cpp line 341:
MoviesTask(moviePtr, 0);

error msg:
Thread 1: Program received signal: “EXC_BAD_ACCESS”

Hi thedofl.

I got same problem.
Any progress on this topic??

Quick workaround.

use ofVideoPlayer as pointer like this

  
  
ofVideoPlayer*	player;  
  

and when re-load movie file,
delete and recreate instance.

  
  
player->stop();  
player->close();  
delete player;  
player = new ofVideoPlayer();  
player->loadMovie(path);       
  

Thanks!
Akira

Are you guys by any chance using OS X?

I had a similar issue and resolved it here: http://forum.openframeworks.cc/t/cannot-switch-movies-with-ofmovieplayer-on-os-x-10.6/5222/0

Hi Akira and nemic,

I’m having the exact same issue you were both having.
The solution Akira came up with seemed to be working fine, I’ve got 1 big issue with it though: It leaks memory. After running my application for a couple of hours my virtual memory reaches 4GB, which causes a crash. My app should run a whole day.
I can’t find the bDoWeAlreadyHaveAGworld boolean in ofVideoPlayer.cpp nemic is talking about. So that solution is not helping me either.

Does anybody have a clue why Akira’s solution has this big memory leak?

Thanks,
Harm

Small update on the question:
After a little more searching I got the solution of nemic (I found the boolean in the ofQuickTimePlayer.cpp file) to work. Yet the result is the same, some memory is still being used by the previous movie, and my memory keeps building up.

Here is a simple code demo, does anybody have an idea about what I’m doing wrong?

  
#include "testApp.h"  
//--------------------------------------------------------------  
void testApp::setup() {  
	playVideo = true;  
	videoWall.loadMovie("flip.mov");    
	videoWall.play();   
}  
  
//--------------------------------------------------------------  
void testApp::update()  
{  
	if (playVideo) videoWall.idleMovie();  
}  
//--------------------------------------------------------------  
void testApp::draw(){  
	if (playVideo) videoWall.draw(0,0,640,480);  
}  
//--------------------------------------------------------------  
void testApp::keyReleased(int key){  
	switch (key) {  
		case 's':  
			playVideo = false;  
			videoWall.stop();  
			videoWall.close();  
			break;  
		case 'p':  
			videoWall.loadMovie("flip.mov");    
			videoWall.play();  
			playVideo = true;  
		default:  
			break;  
	}  
}  
  

It seems to be working now.
I changed my openframeworks verison to 0062.
That fixed it for me.

I am still leaking memory running harmvandeven’s code.

I commented out the line that nemik discovered (so that I can load and play the same video over and over):

  
  
//bDoWeAlreadyHaveAGworld = true;  
  

I am using oF version 0062, Xcode on Mac.

Any ideas?

For me this code works file, I’m also working in Xcode on OS X 10.6.
I’m new to oF so if this doesn’t work I don’t know how to help you.
It reloads te same movie again and again. I’ve created an application which uses this code to switch movies every half a miniute and it’s been running multiple nights without leaks.
I hope this works for you.

  
#include "testApp.h"  
  
//--------------------------------------------------------------  
void testApp::setup(){  
      
    videoWall = 0;  
    startVideo();  
      
    ofSetFrameRate(60);  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
	if (playVideo) videoWall->idleMovie();  
    if((ofGetFrameNum()%400)==0){  
        startVideo();  
    }  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	if (playVideo) videoWall->draw(0,0,640,480);  
}  
  
//--------------------------------------------------------------  
void testApp::keyPressed  (int key){  
	  
}  
  
//--------------------------------------------------------------  
void testApp::keyReleased(int key){  
	switch (key) {  
		case 's':  
			stopVideo();  
			break;  
		case 'p':  
			startVideo();  
		default:  
			break;  
	}  
}  
  
void testApp::startVideo(){  
    if(videoWall){  
        stopVideo();  
    }  
      
    printf("start video\n");  
    playVideo = true;  
    videoWall = new ofVideoPlayer();  
	videoWall->loadMovie("flip_pro.mov");  
	videoWall->play();   
}  
  
void testApp::stopVideo(){  
    printf("stop video\n");  
    videoWall->stop();  
    videoWall->close();  
    delete videoWall;  
    videoWall = 0;  
    playVideo = false;  
}  

I am using version 007 and I am having the same issue. I am loading 15 ofVideoPlayers at random intervals. There is a leak in the real memory that slowly rises over time. This causes the app to crash with the same error explained by thedofl. Sample code below:

  
//--------------------------------------------------------------  
void testApp::setup() {  
    ofSetFrameRate(60);  
	ofSetVerticalSync(true);  
	  
	numFiles = lister.listDir( "renders/" );  
	  
	numColumns	= 5;  
	numRows		= 3;  
	vPadding	= 10;  
	  
	total = numColumns*numRows;  
	  
	for(int i = 0; i < total; i++) {  
		players.push_back( new ofVideoPlayer() );  
		startTimes.push_back( ofGetElapsedTimeMillis() );  
		lengths.push_back( ofRandom(0, 1000) );  
	}  
}  
  
//--------------------------------------------------------------  
void testApp::update() {   
	ofSetWindowTitle( ofToString(ofGetFrameRate(), 0) );  
	  
	for( int i = 0; i < total; i++) {  
		if(ofGetElapsedTimeMillis() - startTimes[i] >= lengths[i]) {  
			players[i]->stop();  
			players[i]->close();  
			delete players[i];  
			players[i] = 0;  
			  
			players[i] = new ofVideoPlayer();  
			string filePath = lister.getPath((int)ofRandom(0, numFiles));  
			players[i]->loadMovie( filePath );  
			players[i]->play();  
			  
			startTimes[i] = ofGetElapsedTimeMillis();  
			lengths[i] = ofRandom(15000, 30000);  
		}  
		players[i]->update();  
	}  
}  
  
//--------------------------------------------------------------  
void testApp::draw() {  
	float ratio	= (float)240.f/(float)320.f;  
	float availW = ofGetWidth() - (vPadding * (numColumns+1));  
	float playerW = (float)availW / (float)numColumns;  
	float playerH = playerW * ratio;  
	  
	int index	= 0;  
	int xIndex	= 0;  
	float x, y;  
	for (int i = 0; i < numColumns; i++) {  
		for (int j = 0; j < numRows; j++) {  
			index	= j*numColumns+i;  
			xIndex					= (i%numColumns);  
			float x					= (xIndex * playerW);  
			float xPadAmt			= ((xIndex+1)*vPadding);  
			x		=  x + xPadAmt;  
			y		= ((j) * playerH) + ((j)*vPadding);  
			  
			players[index]->draw( x, y, playerW, playerH );  
		}  
	}  
}  

And the error that prints out to the console:

  
  
Program received signal:  "EXC_BAD_ACCESS".  
sharedlibrary apply-load-rules all  
warning: .o file "/Developer/usr/lib/gcc/i686-apple-darwin10/4.0.1/libgcc.a(_eprintf.o)" more recent than executable timestamp in   
"/Applications/OpenFrameworks/of_dev/openFrameworks/apps/Gifinator/KinectArnoldCapturev5/bin/ArnoldGifinatorv5Debug.app/Contents/Frameworks/GLUT.framework/Versions/A/GLUT"  
  
warning: Could not open OSO file /Developer/usr/lib/gcc/i686-apple-darwin10/4.0.1/libgcc.a(_eprintf.o) to scan for pubtypes for objfile   
/Applications/OpenFrameworks/of_dev/openFrameworks/apps/Gifinator/KinectArnoldCapturev5/bin/ArnoldGifinatorv5Debug.app/Contents/Frameworks/GLUT.framework/Versions/A/GLUT  
  
warning: Could not find object file   
"/Users/theo/Documents/CODE/__OPENFRAMEWORKS/gitOF/openFrameworks/apps/devApps/macDragDropExample/buildGlutFrameworkHackedWindowLevel10.4/libForeground.a(macx_foreground.o)"   
- no debug information available for "/Users/mcast/Code/GLUT-ToPost/macx_foreground.m".  
  

I’m having the exact same problem as you guys had. I’m using version 007 of openframeworks on Mac os x lion. My code has the same structure: a pointer to an ofVideoPlayer, gets closed, deleted, renewed, loaded and so on. The applications loads full HD motion jpeg mov-files.
When I use Instruments to check the allocations I can see very clearly that the memory is building up every time I close an instance of the videoPlayer.
The applications is running 16 hours every day, and because it runs out of memory after 12 hours the applications crashes.

Did anybody find a solution or some kind of a workaround?

Any help is very much appreciated.

Kind regards,

Jannes

I tested this in Cinder and the same thing happened. Then I tested in the Quicktime player, still leaking. Quicktime seems to keep the memory around, even if you close it!

I ended up loading images and playing them as sequences, but the images were small. I made a threaded player since the loading of images slowed it down a bit.

Hi Nick,
Thanks for the super fast response and the interesting (and also troubling) information. I’ll run a few more test tomorrow. If I can find a way to solve this memory problem I’ll let you know!

Today I got a little help from Jan at Vormplus.be who is a more experienced programmer as it comes to openframeworks. He pointed me to this library made by obviousjim:
https://github.com/obviousjim/FlightPhase-ofxAddons/tree/master/ofxQTKitVideoPlayer

Adding the QTKit and CoreVideo frameworks to my project and changing the ofVideoPlayer to the ofxQTKitVideoPlayer, the memory was under control.
Performance is better and no more memory leaks. And you have almost no code to change.

Thank you very much obviousjim for this wonderful addon!

Thank you for posting your findings. It sounds perfect and I will definitely use this in the future. :slight_smile:

Does anyone know if there is a similar alternative solution for Windows 7? I have the same virtual memory leak others have mentioned above.

The call stack throws error when creating ImgMemAndGWorld() - probobly because there is no more available memory in Virtual Memory.

Private Memory stays around 70 mb
Virtual Memory (Committed Memory in the Memory Monitor) counts gradually up from 100 mb to 2 GIG at which point it crashes.

I tried adding “DisposeMovieController(thePlayer);” to the closeMovie fuction in the QuickTimePlayer based on the apple developer recommendations http://developer.apple.com/library/mac/#documentation/QuickTime/RM/QTforWindows/QTforWindows/C-Chapter/3BuildingQuickTimeCa.html#//apple-ref/doc/uid/TP40000940-BuildingQuickTimeCapabilityIntoaWindowsApplication-SW1

  
void ofQuickTimePlayer::closeMovie(){  
  
	//--------------------------------------  
	#ifdef OF_VIDEO_PLAYER_QUICKTIME  
	//--------------------------------------  
  
	if (bLoaded == true){  
  
	    DisposeMovie (moviePtr);  
  
	    DisposeMovieController(thePlayer); //added because developer site recommended this.   
  
		DisposeMovieDrawingCompleteUPP(myDrawCompleteProc);  
  
		moviePtr = NULL;  
    }  
  
   	//--------------------------------------  
	#endif  
    //--------------------------------------  
  
	clearMemory();  
	bLoaded = false;  
}  

That seemed to slow the memory leak down but it still crashes after a few hours.

Here is how I load an unload the videos:

  
	videos[i]->stop();  
		videos[i]->close();  
  
		ofVideoPlayer* tempPtr = videos[i];  
		videos[i] = new ofVideoPlayer;  
		videos[i]->loadMovie(str1);  
		delete tempPtr;  
		tempPtr = 0;  
  

I feel like I’m really close to fixing this. Anyone have any additional suggestions?

I switched over to the goVideoPlayer by gameover after reading some posts in the forum on the topic there.
No more virtual memory leaks.

So one might be able to locate the problem by comparing the two players to each other. We really could use an overhaul to the videoPlayer in the core framework - there are already much better alternatives out there now.