Resource not available

Hi all,
I have a problem with my OpenGL application…
I realized a 3DLaser Sensor simulator: in a windows I put a point
(glVertex)for every misure made by sensor… when I realize the 9434th
misure and display the 9434th point I get an error:
“A requested resource was not available”.

I’m not using array or display list, only a glVertex3f inside a nested “for” cycle

I think there is a limit in vertex number in OpenGL, is that True? Is there
a way to jump over the problem?

Any subjestion will be really appreciated

Thank you in advance

I’m not using array or display list, only a glVertex3f inside a nested “for” cycle

I think there is a limit in vertex number in OpenGL, is that True? Is there
a way to jump over the problem?

Any subjestion will be really appreciated

Thank you in advance

“A requested resource was not available” is not really an OpenGL error message. Try to find out from where it comes exactly first.
Could be an GL_OUT_OF_MEMORY error masked by some code?

There is no limit in the number of vertices per begin-end.
Some implementations may have bugs, but especially sending GL_POINTS doesn’t impose huge problems for an implementation. Check your glGetString(GL_VENDOR). Microsoft’s implementation is pretty rotten.

If there’s no other way around, don’t use so many points in one primitive but simply send a glEnd-glBegin pair every X vertices. Immediate mode isn’t really fast anyway, so this won’t hurt too much.

Thank you for your reply :slight_smile:
I just tried to put glBegin and glEnd inside the “for”, but I get the same error.

Now I’m trying to get error string just like you said…

It is a great problem because I cannot simulate a scan of a whole world…


If you don’t find it, put some code of the OpenGL initialization and drawing code, or all if it’s not too big.

This is initialization code:

BOOL CLasScanView::SetWindowPixelFormat(HDC hDC)
    int pixelformat; 
    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);			// Set the size of the structure
    pfd.nVersion = 1;									// Always set this to 1
	// Pass in the appropriate OpenGL flags
    pfd.dwLayerMask = PFD_MAIN_PLANE;					// We want the standard mask (this is ignored anyway)
    pfd.iPixelType = PFD_TYPE_RGBA;						// We want RGB and Alpha pixel type
    pfd.cColorBits = SCREEN_DEPTH;						// Here we use our #define for the color bits
    pfd.cDepthBits = SCREEN_DEPTH;						// Depthbits is ignored for RGBA, but we do it anyway
    pfd.cAccumBits = 0;									// No special bitplanes needed
    pfd.cStencilBits = 0;								// We desire no stencil bits
	// This gets us a pixel format that best matches the one passed in from the device
    if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == FALSE ) 
        return FALSE; 
	// This sets the pixel format that we extracted from above
    if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE) 
        return FALSE; 
    return TRUE;

And this is rendering code:

		// Punti verdi
		glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
		for(int i = 0; i < nPiani; i++)
			for(int j = 0; j < nPunti; j++)
				glBegin(g_ViewMode);	// Begin drawing with our selected mode (Points)
					dist = pScan->getPointDist(i,j);;
					if(dist < memComune.maxDepth)
						glVertex3f(pX,pY,pZ); // I segni sono dovuti alle convenzioni scelte
				glEnd();				// End the drawing

				/*unsigned char str[50];
				str = glGetString(GL_VENDOR);

You must initialize your local pfd variable completely or it will not work in release builds. Debug builds normally initialize with zero. The comment about the depth bits is wrong.

The rendering code is so simple that I think the problem is in your code, not in OpenGL.
As I said, debug through all your code and find who sends the error message.

If it happens on the first time you run through that loop it also shouldn’t have to do with other resources. Else check your rendering contexts and HDCs, too.

I don’t think I’ll make a release version.
This program is for my Laura Degree thesis in Informatic Engineering (Robotic branch)and it must work only in debug mode :slight_smile:

Have you any subjestion about how searching where the error message is sent from?
I have no ideas about it :frowning:

Thank you again

Sorry, this is grossly off topic and should be obvious to any programmer.

Consult the manual of your development environment (keys in brackets for MSVC) on how to

  • start the debugger (F5, F10, F11),
  • set and clear breakpoints (F9),
  • single step (F10),
  • single step into (F11).

Put a breakpoint at the beginning of the inner loop’s body and step until you get the error (How did that happen?).

Lookup what i and j are, make the breakpoint conditional to stop one iteration before, run the program again, single step into every function and look what’s going on. Switch to assembly view if you don’t get there in the C code.

It’s all in your hands now.

From my message may seem I’m a beginner, sorry, maybe for my bad english.
With my question I would like to know if there is a tool or other way to find the error, nothing else.

However your help was useful to understand that OpenGL is not the cause of my problem…

Now I have to take another way… maybe it’s an heap problem, or other


Originally posted by Myzhar:

maybe it’s an heap problem

Very unlikely. It has been said before, the most obvious way to pinpoint the problem would be the debugger. Just set a conditional breakpoint that kicks in just before you hit your 9434th vertex, single step, check the call stack and so on…

But you know that already…

Hint: The problem is mostlikly in the API you use to obtain the measure, perhaps you dont use it correctly (i.e. as in not freeing stuff) or its buggy?

Noob or not this really does not belong to this forum, its very basic debugging and “finding bugs in other API’s” business that hasnt anything to do with OpenGL (which you would know if you could be bothered to RTFM).

It wont be the last time you face something like this so learn to deal with it.

… the way I get the misure…
I forgot this before… to simulate the laser scanner I use OpenGL z-buffer in this way:

	glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
	glGetIntegerv(GL_VIEWPORT, viewport);

	winX = (float)rect.right/2;  
	winY = (float)rect.bottom/2; 

	glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
	gluUnProject((int)winX,	(int)winY,	winZ, 
	modelview, projection, viewport, 
	&posX,		&posY,		&posZ);
	dist = sqrt(pow((double)posX,2) + pow((double)posY,2) + pow((double)posZ,2));

These operations are made in a 3D Virtual World imported by 3DStudio Max, I take every mesure after rotating scene of 1° around y axis or x axis.
Is it possible that this code can generate that error, when is repeated 9434 times? It is only an hypothesis…