ofVideoGrabber, ofImage, ofPixels, drawing an unallocated texture

Hi I need help with this:
My program is a video grabber which opens the webcam and allows me to take snapshots whenever I hit a certain key. But this only worked for capturing 9 images(by setting from pixels).

When I press the key for the camera to capture the tenth image, the program runs and doesn’t allow the tenth image to display, but shows this in the black screen:
“[warning] of GLRenderer: drawing an unallocated texture” ,
“[ERROR] ofImage: saveImage(): couldn’t save “sample.png”, pixels are not allocated”
"[ERROR] ofImage: loadImage(): couldn’t load image from “sample.png”

Thanks

maybe you need to post some code here. then we could figure out what’s going wrong

if(key==‘p’){
ofPixels pixels11= vidGrabber.getPixelsRef();

im11.saveImage(“samplea.png”);
im11.loadImage(“samplea.png”);
}

this is for the tenth photo,

check the following code:

testApp.h

#pragma once

#include "ofMain.h"

class testApp : 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 windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);        
        
        ofVideoGrabber         vidGrabber;
        int                 imgW, imgH;
        ofImage img;
        int id;
};

testApp.cpp

#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
    
    id = 0;
    imgW = 640;    
    imgH = 480;
    img.allocate(imgW,imgH,OF_IMAGE_COLOR);
    
    vidGrabber.setDeviceID(0);
    vidGrabber.setDesiredFrameRate(30);
    vidGrabber.initGrabber(imgW,imgH);
    
    ofBackground(255,255,255);
    ofSetFrameRate(30);
    ofSetVerticalSync(true);
}


//--------------------------------------------------------------
void testApp::update(){
    
    vidGrabber.update();
    if(vidGrabber.isFrameNew())
    {
        img.setFromPixels(vidGrabber.getPixelsRef());
    }
}

//--------------------------------------------------------------
void testApp::draw(){
    ofSetColor(255,255,255);
    img.draw(0,0);
    ofSetColor(255,0,0);
    ofDrawBitmapString("id: "+ofToString(id),50,50);
}


//--------------------------------------------------------------
void testApp::keyPressed  (int key){ 
    if(key == 'p' )
    {
        char name[256];
        sprintf(name,"img%d.png",id);
        img.saveImage(name);
        id++;
    }
    
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){ 
    
}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
    
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
    
}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
    
}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){ 

}

thank you, but then again I want to load each image and display them on the screen as a grid of images. and when I attemt to do that using this code it gives me the same error again.

void ofApp::draw(){
ofSetColor(255,255,255);
im1.draw(320,0);
ofSetColor(255,0,0);
ofDrawBitmapString("id: "+ofToString(id),50,50);
}

if(key == ‘p’ )
{
char name[256];
sprintf(name,“img%d.png”,id);
im1.saveImage(name);
im1.loadImage(name);

    id++;
}