Segmentation fault when loading several quicktime movies

Hi,

I am developing a program which allows me to cross-fade between several movies. For that I built a vector where YYY is a class which inside holds an ofMoviePlayer. In my main loop I then call YYY::update() and YYY::draw() for each vector element.

When I only load one movie everything seems to work fine. But when I load two or more movies it crashes even before getting to draw. Actually it crashes when I try to, for example, do ofMoviePlayer::setPosition(0).

This may be my fault, of course, but I still didn’t figure it out. Could this be a bug with Quicktime engine? Are there any known bugs?

Thanks,
Nuno

hmmm…

can you please post a small simple example that shows the problem?

if you use an array does it work?

thanks !
zach

hi zach,

here you are. you just have to make a simple change to the moviePlayerExample:

  1. testApp.h
  
  
#ifndef _TEST_APP  
#define _TEST_APP  
  
#include "ofMain.h"  
#include "ofAddons.h"  
#include <vector>  
  
class testApp : public ofSimpleApp{  
  
	public:  
  
		testApp();  
		void setup();  
		void update();  
		void draw();  
  
		void keyPressed  (int key);  
		void keyReleased(int key);  
		void mouseMoved(int x, int y );  
		void mouseDragged(int x, int y, int button);  
		void mousePressed(int x, int y, int button);  
		void mouseReleased();  
  
		vector<ofVideoPlayer> movies;   // <<<<< new variable  
		ofVideoPlayer fingerMovie;  
};  
  
#endif  
  

  1. testApp::Setup() in testApp.cpp:
  
  
void testApp::setup(){  
	ofBackground(255,255,255);  
	fingerMovie.loadMovie("movies/fingers.mov");  
	fingerMovie.play();  
	movies.push_back(fingerMovie);   // <<< remove this line and it's ok  
  
  ofVideoPlayer *movie;  
  movie = new ofVideoPlayer();  
  movie->loadMovie("movies/fingers.mov");  
  movies.push_back(*movie);  
  
  movie = new ofVideoPlayer();  
  movie->loadMovie("movies/fingers.mov");  
  movies.push_back(*movie);  
}  
  

So:

  • if you don’t add the fingerMovie to the vector everything works fine.
  • if you add fingerMovie but comment out the 2nd and 3rd movies everything also works fine.

Please note that I didn’t change the rest of the code. I simple add the movie together with two other movies to a vector which is not even used.

I hope this helps.

Please let me know if this is indeed a bug or if I’m doing something wrong.

Thanks,
Nuno[/list][/list]

Hi

Not completely sure, but i think it has to do with the way you’re adding movies to the vector.

Try this:

testApp.h

  
 vector<ofVideoPlayer*> movies;   // <<<<< new variable  

testApp.cpp

  
movies.push_back(movie);  

ok – I know the problem… when you use push_back and pass in the object, it’s doing pass by copy. When it does that, it’s doing some stuff that doesn’t do a proper clone of the object… some info is here:

http://www.codersource.net/cpp-copy-constructors.html

We’ve fixed it for ofImage, for example:

  
  
ofImage(const ofImage& mom);	// allocate in pass by copy  
ofImage& operator= (const ofImage& mom); 	// copy via =, ie. imga = imgb;  
  

but we have still to add it to some OF objects.

for now, you can either (a) use pointers in the vector, or (b) use an array. I can help with either if you want.

we’ll take a look at fixing this shortly…

thanks!!
zach

Hi arturo and zach,

Thank you for your quick answer!

To be honest, I’m a little afraid of getting tangled in c++ programming. I was using vvvv which is quite fast and easy to code. But since I’m switching to mac I decided to give OF a try. I am quite impressed. And since I’d rather code than patch, I’d really like to adopt it.

But this kind of errors gets me scared because I don’t want to get stuck in this kind of low level stuff which c++ is so full of. I was about to give up on using OF for this project, but if I keep getting such a good support from the community I’m willing to keep on trying :wink:

Thanks!

Nuno

Or you could just do this with the same code you had in your header file
This should work well if you don’t need to be dynamically adding and removing movies from your vector - otherwise arturo’s example should work well for that.

  
void testApp::setup(){   
  
   ofBackground(255,255,255);    
  
   //we are going to load and play 3 movies  
  
   //assign space for the 3 ofVideoPlayer objects   
   movies.assign(3, ofVideoPlayer);  
  
   //now just load the movies   
  
   movies[0].loadMovie("movies/example1.mov");   
   movies[0].play();   
  
  movies[1].loadMovie("movies/example2.mov");   
  movies[1].play();  
  
  movies[2].loadMovie("movies/example3.mov");   
  movies[2].play();  
  
}  

Hope that helps!
Theo

Understood. I think I’ll use a vector of pointers since it completely bypasses the problem. But your example made me better understand what the problem is.

Thanks!
Nuno

But this kind of errors gets me scared because I don’t want to get stuck in this kind of low level stuff which c++ is so full of. I was about to give up on using OF for this project, but if I keep getting such a good support from the community I’m willing to keep on trying

yep totally – it’s not that easy to solve errors, especially language issues, but for us this kind of posting is good because:

a) we learn about usage, and that shows us flaws in the code (like ofVideoPlayer can’t be used in a vector). there is much we are not able to predict, so feedback is very helpful.

b) it is googleable and linkable – and therefore good for folks in the future

c) alot of c++ stuff is hard to know, and everyone does stuff differently, so it’s good to jot down different ideas and solve problems with others.

anyway, happy to help!

good luck –
zach

ps : this is useful to keep track of the most recent stuff on the forums –
http://www.openframeworks.cc/forum/rss.php
many of us use it :slight_smile: