Public Group

Archived

This topic is now archived and is closed to further replies.

"Expression cannot be evaluated" Error

This topic is 5762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I''m attempting to create a particle system following Tricks of the Windows Gurus and I''ve got to the point where the particle is shown on the screen but when the program exits I get a popup of "Your program has encountered a problem." Using the debugger I''ve traced the problem to this line...
  video_buffer[x + y*lpitch16] = _RGB16BIT565(255,0,0);
and the debugger reports "Error: Expression cannot be evaluated". The weird thing is the particle IS displayed so things appear to work until I exit. I don''t know how to fix this error, can someone please help me?

Share on other sites
if you''d given some information on the types involved in that statement, one might be able to say if something is wrong with it. Please do tell us what types video_buffer, x, y and lpitch16 are. Also what domains those values are in, could be interesting.

The error "Error: Expression cannot be evaluated" is most likely not relevant. I''m not 100% sure, but I seem to recall VC to complain something similar when you try to view a variable by an expression which cannot be evaluated.

Most likely, your function is probably messing with memory it shouldn''t. I think your debug build will call a function upon function return to check that the heap and stack are intact, in if they''re not, throws an exception at you.

Share on other sites
Sorry for not making that clear enough, I'll post the whole function including definitions. BTW I'm following along with Tricks.. so these are all from that.

                ///////////////////////////////////////////////////////////////////// Draws the particle to screen//void CParticleEngine::DrawParticles(LPDIRECTDRAWSURFACE7 lpdds){	// Lock the back buffer	DDSURFACEDESC2 ddsd;	ZeroMemory(&ddsd, sizeof(ddsd));	// This is so the functions know how big the ddsd variable is.	ddsd.dwSize = sizeof( ddsd );	lpdds->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL);	// Pointer to video memory	USHORT video_buffer = (USHORT *)ddsd.lpSurface;	// Calculate lpitch	int lpitch16  = (ddsd.lPitch >> 1);	// Go through all particles, test if alive	for (int index = 0; index < MAX_PARTICLES; index++)	{		if (particles[index].state == PARTICLE_STATE_ALIVE)		{			video_buffer[particles[index].x + particles[index].y*lpitch16] = _RGB16BIT565(0,0,255);		}	}	// Unlock the back Surface	lpdds->Unlock(NULL);}

_RGB16BIT565 is a macro used to convert RGB into 5,6,5 format and is defined as...
#define _RGB16BIT565(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))

[edited by - punx409 on February 3, 2003 11:03:34 PM]

Share on other sites
Okay, from fooling around with my program I now know that I''m getting this error because when ESC is pressed and the program exits the program still tries to use video_buffer, when it doesn''t exist.

Would the best way of handling this be a if (videobuffer) {} or is there something else I''m not doing in cleanup?

Share on other sites
You should examine why any code touching the surface is executed after it is released; that should not happen. Then it is good practice to always nullify something that has been released, and to check it before using it. But that is really a sort-of workaround in this case, as I think - I don''t know a lot of your program''s structure - that it would only "hide" some other error in your design.

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• Forum Statistics

• Total Topics
633308
• Total Posts
3011293
• Who's Online (See full list)

There are no registered users currently online

×