oFApp crashes on Mac mini


#1

Hello. I’ve an app which uses vidgrabber to catch webcam stream and then it mixes jpges from a folder to the stream. The App runs alright when I’m running it on my macbook pro 10.10.5 (Yosemite) but when I’m running it on mac mini 10.10.7 (Yosemite aswell) it always crashes after about half an hour or so. On my laptop I was able to run it for about 1.5 hours without problems and it didn’t crash at all. The only difference is that I’m using an external webcam on the mini. I also tried to use try{}catch{} but wasn’t of any help. My only guess it somewhere with some random values an indexOutOfBounds happens but can that be it because I think I’ve taken care of that? Any ideas what might be the problem, like is there something I need to take account when building for mac mini? Here’s the crash report:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff906e8286 __pthread_kill + 10
1 libsystem_c.dylib 0x00007fff95322a53 __abort + 145
2 libsystem_c.dylib 0x00007fff953229c2 abort + 144
3 libGPUSupport.dylib 0x000000011438c4c4 gpusKillClient + 94
4 com.apple.driver.AppleIntelHD3000GraphicsGLDriver 0x0000000113f0b5fe GhalInterface::getCommandBuffer(unsigned char**, unsigned char**, unsigned int*, unsigned int*) + 158
5 com.apple.driver.AppleIntelHD3000GraphicsGLDriver 0x0000000113f2d718 GHAL3D::CPrivateCommandTransport::FlushCommandBuffer(GHAL3D::FLUSH_TYPE, unsigned char) + 280
6 com.apple.driver.AppleIntelHD3000GraphicsGLDriver 0x0000000113f2d44d g575SubmitPacketsToken + 64
7 com.apple.driver.AppleIntelHD3000GraphicsGLDriver 0x0000000114204201 gldPresentFramebufferData + 127
8 GLEngine 0x00007fff98566131 glSwap_Exec + 97
9 com.apple.opengl 0x00007fff97717fba CGLFlushDrawable + 66
10 com.apple.AppKit 0x00007fff8ac10e2b -[NSOpenGLContext flushBuffer] + 27
11 cc.openFrameworks.ofapp 0x000000010e072852 ofAppGLFWWindow::draw() + 130
12 cc.openFrameworks.ofapp 0x000000010e017a05 ofMainLoop::loopOnce() + 197
13 cc.openFrameworks.ofapp 0x000000010e01790e ofMainLoop::loop() + 62
14 cc.openFrameworks.ofapp 0x000000010dfe8e36 ofRunApp(std::__1::shared_ptr) + 86
15 cc.openFrameworks.ofapp 0x000000010dfe8d8b ofRunApp(ofBaseApp*) + 75
16 cc.openFrameworks.ofapp 0x000000010dc0b49a main + 74
17 cc.openFrameworks.ofapp 0x000000010dc0b444 start + 52

Thanks for help!


#2

I tried to run it on my laptop again and it ran for hours without problems. So is it a build thing, like do I have to make some settings for the build phases or something when building for the mac mini?


#3

well, it certainly has to do with the GPU. MacMinis only have the intel integrated GPU, which might not have the necessary specs to run your app. Which laptop do you have? Does it have more than one GPU? what are you trying to do in your ofApp ?


#4

I have macbook pro early 2015 with Intel Iris Graphics 6100 1536 MB.

My app is based on the web camera vidgrabber example. Basicly what I’ve changed is that now it loads bunch of jpges to vector in the setup:

//loading pictures
dir.listDir("images");
pics.resize(dir.size());
for (int i = 0; i < dir.size(); i++) {
    pics[i].load(dir.getPath(i));
}
dirSize = dir.size();

Then the update function is slightly modified version witch some randomization with modulos and the jpeg files are mixed randomly into the webcam stream:

void ofApp::update(){
	//grab a new frame
	vidGrabber.update();
	
    int cealing = int(ofRandom(2,1000));
    int divider = int(ofRandom(1, 10));
    int movement = int(ofRandom(0, 10));
	//update the mesh if we have a new frame
	if (vidGrabber.isFrameNew()){
		for (int i=0; i<vidGrabber.getWidth()*vidGrabber.getHeight(); i++){
            if (i% divider != 0) {
                ofFloatColor sampleColor(vidGrabber.getPixels()[i*3]/255.f,// r
                                     vidGrabber.getPixels()[i*3+1+movement]/255.f,//g
									 vidGrabber.getPixels()[i*3+2]/255.f);// b
			
			//now we get the vertex at this position

			ofVec3f tmpVec = mainMesh.getVertex(i);
			mainMesh.setVertex(i, tmpVec);
            mainMesh.setColor(i, sampleColor);
            }else {
                ofVec3f tmpVec = mainMesh.getVertex(i);
                mainMesh.setVertex(i, tmpVec);
                
            }
		}
        for (int j = 0; j < 10; j++) {
            int startX = (rand()%int(vidGrabber.getWidth()));
            int startY = (rand()%int(vidGrabber.getHeight()));
            
            int xAdd = rand()%((rand()%20)+20);
            int yAdd = rand()%((rand()%20)+30);
            int picNumber = rand()%dirSize;
            for (int x = startX; x< xAdd+startX; x++) {
                for (int y = startY; y <yAdd+startY; y++) {
                    int indexNumber = x + vidGrabber.getWidth() * y;
                    mainMesh.setColor(indexNumber, pics[picNumber].getColor((x+cealing)%int(pics[picNumber].getWidth()),y%int(pics[picNumber].getHeight())));
                }
            }
        }
	}
	
	//let's move the camera when you move the mouse
	float rotateAmount = ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, 360);
	
	//move the camera around the mesh
	ofVec3f camDirection(0,0,1);
	ofVec3f centre(vidGrabber.getWidth()/2.f,vidGrabber.getHeight()/2.f, 255/2.f);
	ofVec3f camDirectionRotated = camDirection.getRotated(rotateAmount, ofVec3f(1,0,0));
	ofVec3f camPosition = centre + camDirectionRotated * extrusionAmount;
	
	cam.setPosition(camPosition);
	cam.lookAt(centre);
}

So yeah I really don’t know where to start the debugging. Of course I’m totally newbie with OF and C++ so my code might be awful in many aspects, in this case at least from the viewpoint of GPU clearly :smiley: Might it help if I install xcode and of to the macmini and build it on it? I’m really helpless with this problem so any tip is greatly appreciated. Thanks!


#5

Hi, so how much images are you loading at start up?. This might be the problem. ofImage automatically allocates a GPU texture, so you might be running out of gpu memory. If you are not drawing these images, before loading call setUseTexture(false) on each ofImage of the vector. This will not allocate the texture.
let me know how it goes.
best


#6

Thank you for your reply. I’ve got only 4 pics in the folder. So it is not much. I made that setUseTexture(false) and fixed a thing that might cause index out of bounds but it is still not working. It opens up, runs perfectly for about 30 minutes or so and then it crashes with that error message stated above. The vidgrabbers resolution is only:

	vidGrabber.setVerbose(true);
	vidGrabber.setup(320,240); 

So it is not much at all either. Can it be that the 10.10.5 and 10.10.7 are different some way which causes the crash?


#7

Hi, can you post the complete code please?


#8

Sure thing. Here’s ofApp.h

#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{
	
public:
	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(int x, int y, int button);
	void mouseEntered(int x, int y);
	void mouseExited(int x, int y);
	void windowResized(int w, int h);
	void dragEvent(ofDragInfo dragInfo);
	void gotMessage(ofMessage msg);

    
	ofCamera cam; // add mouse controls for camera movement
	float extrusionAmount;
	ofVboMesh mainMesh;
	ofVideoGrabber vidGrabber;
    vector <ofImage> pics;
    ofDirectory dir;
    int dirSize;
	
};

Then the Setup:

void ofApp::setup(){
    
    
    ofSetDataPathRoot("../Resources/data/");

	ofSetVerticalSync(true);
	ofSetFrameRate(60);
	ofBackground(66,66,66);
	
	//initialize the video grabber
	vidGrabber.setVerbose(true);
	vidGrabber.setup(320,240);

	//store the width and height for convenience
	int width = vidGrabber.getWidth();
	int height = vidGrabber.getHeight();
    
    
    //loading pictures
    dir.listDir("images");
    pics.resize(dir.size());
    for (int i = 0; i < dir.size(); i++) {
        pics[i].load(dir.getPath(i));
        pics[i].setUseTexture(false);
    }
    
    dirSize = dir.size();


	
	//add one vertex to the mesh for each pixel
	for (int y = 0; y < height; y++){
		for (int x = 0; x<width; x++){
			mainMesh.addVertex(ofPoint(x,y,0));	// mesh index = x + y*width
												// this replicates the pixel array within the camera bitmap...
			mainMesh.addColor(ofFloatColor(0,0,0));  // placeholder for colour data, we'll get this from the camera
		}
	}
	
	for (int y = 0; y<height-1; y++){
		for (int x=0; x<width-1; x++){
			mainMesh.addIndex(x+y*width);				// 0
			mainMesh.addIndex((x+1)+y*width);			// 1
			mainMesh.addIndex(x+(y+1)*width);			// 10
			
			mainMesh.addIndex((x+1)+y*width);			// 1
			mainMesh.addIndex((x+1)+(y+1)*width);		// 11
			mainMesh.addIndex(x+(y+1)*width);			// 10
		}
	}
	
	//this is an annoying thing that is used to flip the camera
	cam.setScale(1,-1,1);
	
	
	//this determines how much we push the meshes out
	extrusionAmount = 0.0;
}

The Update:

void ofApp::update(){
	//grab a new frame
	vidGrabber.update();
	
    int cealing = int(ofRandom(2,1000));
    int divider = int(ofRandom(1, 10));
    int movement = int(ofRandom(0, 10));
	//update the mesh if we have a new frame
    
	if (vidGrabber.isFrameNew()){
		//this determines how far we extrude the mesh
        
            
        
		for (int i=0; i<vidGrabber.getWidth()*vidGrabber.getHeight(); i++){
            
       

            if (i% divider != 0) {
                
                ofFloatColor sampleColor(vidGrabber.getPixels()[i*3]/255.f,				// r
									 
                                     vidGrabber.getPixels()[i*3+1+movement]/255.f,
                                     
                                     
									 vidGrabber.getPixels()[i*3+2]/255.f);			// b
			
			//now we get the vertex aat this position
			//we extrude the mesh based on it's brightness
			ofVec3f tmpVec = mainMesh.getVertex(i);
			mainMesh.setVertex(i, tmpVec);
            mainMesh.setColor(i, sampleColor);
            }else {
                ofVec3f tmpVec = mainMesh.getVertex(i);
                mainMesh.setVertex(i, tmpVec);
                
            }
		}
        for (int j = 0; j < 10; j++) {
            int startX = (rand()%int(vidGrabber.getWidth()));
            int startY = (rand()%int(vidGrabber.getHeight()));
            //naita suurentamalla voi kasvataa pikselien kokoa
            int xAdd = rand()%((rand()%20)+20);
            int yAdd = rand()%((rand()%20)+30);
            int picNumber = rand()%dirSize;
            
            //check that won't go out of index
            if(xAdd+startX >= vidGrabber.getWidth()) {
                startX -= xAdd;
            }
            if(yAdd+startY >= vidGrabber.getHeight()) {
                startY -= yAdd;
            }
            
            for (int x = startX; x< xAdd+startX; x++) {
                for (int y = startY; y <yAdd+startY; y++) {
                    
                    int indexNumber = x + vidGrabber.getWidth() * y;
                    //skippaa Y määrän rivejä, että pääsee oikealle riville,
                    //esim jos x=0 ja y=5 niin Y*ruudun koko, niin tullaan oikeaan indeksiin
                    //mainMesh.setColor(indeksi, kuva.getColor(x+katto,y));
                    mainMesh.setColor(indexNumber, pics[picNumber].getColor((x+cealing)%int(pics[picNumber].getWidth()),y%int(pics[picNumber].getHeight())));
                }
            }
        
        }
        
        
	}
    
	
	//let's move the camera when you move the mouse
	float rotateAmount = ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, 360);

	
	//move the camera around the mesh
	ofVec3f camDirection(0,0,1);
	ofVec3f centre(vidGrabber.getWidth()/2.f,vidGrabber.getHeight()/2.f, 255/2.f);
	ofVec3f camDirectionRotated = camDirection.getRotated(rotateAmount, ofVec3f(1,0,0));
	ofVec3f camPosition = centre + camDirectionRotated * extrusionAmount;
	
	cam.setPosition(camPosition);
	cam.lookAt(centre);
}

Then the Draw:

void ofApp::draw(){
	//we have to disable depth testing to draw the video frame
	ofDisableDepthTest();
//	vidGrabber.draw(20,20);
	
	//but we want to enable it to show the mesh
	ofEnableDepthTest();
	cam.begin();		

	//You can either draw the mesh or the wireframe
    //mainMesh.drawWireframe();
    //mainMesh.drawVertices();
    mainMesh.drawFaces();
	cam.end();
	
	//draw framerate for fun
	ofSetColor(255);
	//string msg = "fps: " + ofToString(ofGetFrameRate(), 2);
	//ofDrawBitmapString(msg, 10, 20);
	
}

#9

Hi,
some suggestion first unrelated to your problem.
you can use an ofEasyCam object instead of the ofCam and it will provide all the needed mouse interactions.

The following line has a potential out of bounds.

In the following, startX could become negative if xAdd is more than startX, same for startY.

I can see that your code comes from the meshFromCamera example. Do you also have this problem on the macMini if you run the meshFromCamera example? If there´s no problem then the bug must be in your code, otherwise it should be in the example or in OF itself.


#10

Thanks for reply and help! And you are right about those indexOutOfBounds, fixed them.

I also tried now with the plain ofMeshFromCamera without any of my own code and it still crashes. So the problem is in the example or in OF :frowning: Hmm, don’t know what to do now. The code is from the oF 0.92. I took that version because I couldn’t run the version in 0.9.8 for some reason.

EDIT:

Okay I tried it with the 0.9.8 version now without any of my own code and it still crashes.


#11

that’s odd.
are you compiling on the macmini? if not try it. you’ll need to install xcode (or whichever other IDE you might be using).
It the problem persists.
run in debug mode and once the app crashes you’ll be able to inspect which line of code crashed along with the allocations present, etc. I think this would be the proper and fastest way to debug


#12

like @roymacdonald says – compiling in debug can be helpful so you get a stack trace on crash.

some other ideas (I didn’t look at your code, so this is off the top of my head) for debugging apps that run differently on different machines:

  • variables that are not initialized (they can have random values and give different results across machines)
  • array access (memory errors can happen on one machine and not another)
  • watch memory usage to look for memory leaks

usually running in debug is a great way to view crashes to get actionable info. Another thing to try is removing chunks of code until the crash no longer happens. often I will comment out all of ofApp::draw or ofApp::update to try to figure out what section of code is causing the crash and iteratively uncomment code to help me track where the problem lies.


#13

Hi @zach
The odd thing is that the meshFromCamera example is crashing too.
@Buoyancist please let us know if you figure out what is happening and if this is related to the example or if it is a bug in OF in order to fix it.


#14

Okay so I installed xcode 7.1.1 to the macmini (os x 10.10.7) and ran the meshFromCamera in debug mode to see why it crashes and here’s the screenshot of the xcode screen:

So the case is the same. It rans totally okay for about half an hour and then it crashes. So is the problem in that ofAppGLFWWindow? Sorry about the missing code lines in the screenshot, just noticed them now. So is there something I can do to fix this?

And thanks a lot for your patience and help, I appreciate it a lot. This is a great forum :slight_smile:

EDIT: The only thing I changed in the example is that I set the extrusionamount to zero because I want to have a flat image but I don’t think that should be the reason!

EDIT #2: The line in the ofAppGLFWWindow.cpp that crashes is 395.


#15

So what’s the verdict on this, is it a bug in OF that which makes the meshFromCamera crash on mac mini? And is there something I can do to prevent it from happening?

To summarize this thread/topic: meshFromCamera example crashes on mac mini 10.10.7 and of 0.9.8, screen shot from the debug is in the reply above. The only thing changed in the meshFromCamera example was the extrusion amount and that shouldn’t be the problem as far as I know.


#16

tbh it’s kind of hard to say…

can you make sure that it’s not something unrelated such as power management (monitor going to sleep) or something that happens at some point over time? since it’s a windowing issue, I wonder about those kinds of things (like if the mac mini doesn’t have an output maybe it crashes then). also what kind of camera are you using? maybe switch up the camera might also help ?

I would try commenting out parts of the code to see if there are specific things that are causing the crash. If you don’t do pixel access on the video grabber does it crash? If you remove the mesh but keep the pixel access on video grabber does it crash?

I feel like narrowing down the crash cause will be helpful. the debug things seems uninformative but you might poke around some of the other threads (this is showing thread 1) to see if there’s any useful data.