Advertisement

Question about NT/2000 vs 98

Started by November 13, 2001 11:43 AM
5 comments, last by HardSniper 23 years, 3 months ago
I am writing a program in which I need to display text on the screen at the same time I am displaying graphics. The code I have compiles and runs perfectly under win98, but on my professor's computers(one NT, the other Win2K), it crashes when I run it returning a memory error? It will run fine on his computers if I comment out the text section. I am using the print function from NeHe's 13th tutorial to display the text... Here's the code just in case it'll help...
    
GLvoid glPrint(const char *fmt, ...)			
// Custom GL "Print" routine

{
	char text[256];		// Holds the string

	va_list	ap;		// Pointer to list of arguments


	if(fmt == NULL)		// If there is no text

		return;		// Do nothing


	va_start(ap, fmt);	// Parses the string for variables

	vsprintf(text, fmt, ap);// And converts symbols to numbers

	va_end(ap);		// Reslts are stored in text


	glPushAttrib(GL_LIST_BIT);	// Pushes the display list bits(prevents glListBase from affecting any other display lists used in the program)

	glListBase(base - 32);		// Sets the base character to 32


	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// Draws the display list text after getting length of string 'text'

	glPopAttrib();			// Pops the display list bits(sets GL back to how it was before I set the base setting using glListBase(base-32))

}
    
Does anyone have an idea of what the problem is? HardSniper Edited by - HardSniper on November 13, 2001 12:44:34 PM
HardSniper
Just what exactly is the error? NT4/5 catches all the sloppy code that win9x can''t. Sounds like a pointer error.

Advertisement
I''m not on my professors machine now, but it was something like memory error at 0x000000 or something to that effect...

HardSniper
HardSniper
"Could not access memory at location 0x0000000" or something? If I remember correctly, this is usually caused by a null pointer exception, or by overrunning the bounds of an array. I think it''s usually the latter, where you are trying to do something like list[9] = 3, when list is an array of 8 elements. Maybe that will help.
"Could not access memory at location 0x0000000" or something? If I remember correctly, this is usually caused by a null pointer exception, or by overrunning the bounds of an array. I think it''s usually the latter, where you are trying to do something like list[9] = 3, when list is an array of 8 elements. Maybe that will help.
It''s got nothing to do with unicode. All the libraries for NT implement non-unicode versions (all they do is convert all your text strings to unicode before calling the "proper" functions). It is recommended you use unicode on Windows NT/2000, but this is only a performance concern, since converting from ANSI strings to unicode is time-consuming.

There is possibly a few reasons for your problem. The most likely is that you call glPrint incorrectly. Code like this:

  glPrint( "Number 1: %d, Number 2: %d", 1 );  


will compile with no trouble, but will give you access violations (since vsprintf will be expecting two integer arguments but only gets one). Also, code like this:

  glPrint( "String: %s, Number: %d", 1, "Hello" );  


Will also compile without problems, but will cause problems when vsprintf is looking for a string and finds an integer, or finds a string when looking for an integer (though the latter would work OK, since a string is just a pointer, which in turn is just an integer).

If you suspect this is the problem, try commenting out the vsprintf stuff and just call glCallLists() on fmt instead of text. See how that goes.

Any code that runs under Windows 95 should work on Windows NT/2000 - as long as they "play nice". Windows NT/2000/XP are move unforgiving of incorrect parameters and such (just like Windows 95 is more unforgiving than was Windows 3.1)


codeka.com - Just click it.
Advertisement
Thanks for the help guys, I will try out the different solutions today when I go to his office.

HardSniper
HardSniper

This topic is closed to new replies.

Advertisement