Extreme weirdness with ofTexture and vectors. Please help my sanity!

Hi guys, i’ve just found a bug that has halted my development using 0073. The following simple code works in 0071 and earlier but for some reason does not work in 0073.

Basically im loading the frames of a video into a vector using ofTexture and then accessing those textures from inside the vector. This has always worked but for some reason 0073 wont display anything but the 1st texture stored in the vector…?

I cant seem to work out how to debug this at all or what part of this code may have broke because of 0073…

testApp.h

  
#include "ofMain.h"  
  
class testApp : public ofBaseApp{  
	public:  
		void setup();  
		void draw();  
		void mouseMoved(int x, int y);  
  
        ofVideoPlayer video;  
        vector<ofTexture*>	frames;      // This is the container to play videos  
  
        int pos;  
        float progress; //to iter through frames on loading  
  

testApp.cpp

  
#include "testApp.h"  
  
//--------------------------------------------------------------  
void testApp::setup(){  
  
    video.loadMovie("fingers.mov");  
	video.setPaused( true );  
	  
	for (int i=0; i<video.getTotalNumFrames(); i++){  
		progress = i / (float) ( video.getTotalNumFrames() - 1);	//Value between 0 and 1.  
		video.setPosition( progress );  
		  
		ofTexture* tex;  
		tex = new ofTexture();  
		tex->allocate( video.getWidth(), video.getHeight(), GL_RGB );  
		tex->loadData( video.getPixels(), video.getWidth(), video.getHeight(), GL_RGB );  
		  
		frames.push_back ( tex );  
	}  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
    frames.at(pos)->draw(0,0,ofGetWidth(),ofGetHeight());  
}  
  
//--------------------------------------------------------------  
void testApp::mouseMoved(int x, int y){  
    pos = ofMap(mouseX,0,ofGetWidth(),0,video.getTotalNumFrames());  
}  
  

are you in osx? the default videoplayer has changed and it seems that changing position, speed… is slower now, so calling video.setPosition() won’t change the position immediately, probably if you wait some milliseconds after each call to setPosition it’ll fix your problem

also call update after each call to setPosition

Hey thanks for the suggestions Arturo. I have changed the video to use ofQTKitPlayer instead of ofVideoPlayer, am calling video.update() after setting the position, and am introducing 100 milliseconds of a gap between each call but the same problem is happening.

I’ve included the updated setup code below… any other ideas would be greatly appreciated!

  
//--------------------------------------------------------------  
void testApp::setup(){  
  
    video.loadMovie("fingers.mov");  
	video.setPaused( true );  
	  
	for (int i=0; i<video.getTotalNumFrames(); i++){  
		progress = i / (float) ( video.getTotalNumFrames() - 1);	//Value between 0 and 1.  
		video.setPosition( progress );  
                video.update(); //New method call  
		  
		ofTexture* tex;  
		tex = new ofTexture();  
		tex->allocate( video.getWidth(), video.getHeight(), GL_RGB );  
		tex->loadData( video.getPixels(), video.getWidth(), video.getHeight(), GL_RGB );  
		  
		frames.push_back ( tex );  
                ofSleepMillis(100); //New method call  
	}  
}  
  

i would try the sleepMillis call between setPosition and update and try to make it longer till it works

I’ve put the ofSleepMillis in between setPosition and update and have set the delay between each call to 2000 millis and it still doesn’t work. Apart from the fact it takes a few minutes to load the app even with just a 7 second video, surely there has to be a better solution to getting this working.

Im not sure I really understand how this technique that I have been using for years in many apps has fallen apart so terribly with 0073…?

because the new ofVideoPlayer is based on qtkit, previously it used quicktime which is deprecated now. qtkit has some advantages but seems to have some problems with changing speed, position… responsively, probably because internally it uses a more threaded aproach, making it more difficult to respond faster to these kind of changes. can you put an issue in github with a link to this thread? i haven’t really used the new video player in osx, probably one of the developers of the new code will be of more help

Ok thanks Arturo have just posted an Issue to github then. Fingers crossed one of the devs can come up with a usable solution or I may be in a bit of trouble.

That makes sense about qtKit and the threading calls probably getting in the way of doing speedy calls with ofVideoPlayer. Although this probably has some advantages under the hood this is pretty fatal for using it in a lot of different techniques.

btw, can you try unpausing the video?

YES!!! Oh my god thats got it working! far out I knew it had to be a simple fix. Thanks a million for helping out Arturo. Life can now continue. :slight_smile:

I’ve taken out the update and ofSleepMillis calls as well and it still works.

Feel free to close the github issue if you want but it sounds like there could be some minor tweaking improvements that could happen under the hood but ill leave that up to you and the other devs.