Possible SDL Bug in Windows Vista

Hi,

I recently started to learn using SDL, and I encountered a problem and asked
someone about it, and they suggested that I post it here as they thought it
could be a possible bug.

I was playing around and attempting to develop functions for printing text to
a screen immediately and over time (as if the text were being typed). The way
I initially designed it, I made a function with the following definition:

void write_text_instant( int x, int y, SDL_Surface* destination, SDL_Surface*
screen, std::string message, std::string FONT );

This function would open up the font designated in FONT, print the entire
message out on the destination surface at the given ( x, y ) coordinate, and
then close the font file.

I then made a function that had this definition:

void type_text( int x, int y, SDL_Surface* destination, SDL_Surface* screen,
std::string message, std::string FONT );

This function would create a temporary string where I would put the string
message into it character by character, and each time I added a new character,
I would call write_text_instant.

This method was very slow, but it achieved it’s goal. But with the functions
like this, I encountered the problem that is the potential bug. When my text
functions were running, if I clicked on anything other than the window to my
program, it would stop responding. I would have to bring up task manager and
have windows force the program to close.

I’ve changed the write_text_instant function to take an SDL_Font object
instead of opening one everytime, and it runs ten times faster and does not
have this error anymore. Any ideas?

Thanks!
Daniel

Hello !

Did you test the examples that come with SDL,
if they are showing the same error ?

Would it be possible to upload your routine somewhere
so that people can have a look at it ?

CU

Torsten Giebl <wizard syntheticsw.com> writes:

Hello !

Did you test the examples that come with SDL,
if they are showing the same error ?

Examples come with SDL? No, I didn’t test any examples, only my own written
code.

Would it be possible to upload your routine somewhere
so that people can have a look at it ?

CU

These are the functions that cause my program to behave in the manner it does:

void write_text_instant( int x, int y, SDL_Surface* destination, SDL_Surface*
screen, std::string message, std::string FONT )
{
TTF_Font *font = NULL;
SDL_Surface *text = NULL;
SDL_Color textColor = { 0, 0, 0 };
font = TTF_OpenFont( FONT.c_str(), 12 );

//Render the font
destination = TTF_RenderText_Solid( font, message.c_str(), textColor );

//Apply the font to the screen at the indicated location
apply_surface( x, y, destination, screen);

//Update the screen
SDL_Flip( screen );

//Cleanup
SDL_FreeSurface( text );
TTF_CloseFont( font );

}

void type_text( int x, int y, SDL_Surface* destination, SDL_Surface* screen,
std::string message, std::string FONT )
{
std::string part_message;
char letter = ’ ';
int i = 0;
int size;

//Get size of the message to be printed
size = message.size();

//Loop through the message to be printed
while( i != size )
{
	//Pick out the next letter to be printed
	letter = message[i];

	//Add the letter to the part of the message already printed
	part_message = part_message + letter;

	//Write the new message to the screen
	write_text_instant( x, y, destination, screen, part_message, 

FONT );

	//Move to the next letter in the message
	i++;

	//Pause before moving to the next letter
	SDL_Delay( 30 );

}

}

I had to recreate them as I changed the way they work for efficiency, and to
remove this problem.

In testing these recreations, I called type_text with a message and then
clicked on an AIM window. That caused the program to not respond, and so I
clicked back on it. Then a few seconds later the entire string I passed to it
was typed. I tried pressing enter (the program was waiting for me to do so),
and then windows said it froze and was looking for a solution. But something
is definately odd with this code.

Also, here is my apply_surface function that is called above:

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface*
destination )
{
//Make a temporary rectangle to hold the offsets
SDL_Rect offset;

//Give the offsets to the rectangle
offset.x = x;
offset.y = y;

//Blit the surface
SDL_BlitSurface( source, NULL, destination, &offset );

}

Hope these help.
-Daniel

Hi!

Daniel Maize schrieb:

Hello !

Did you test the examples that come with SDL,
if they are showing the same error ?

Examples come with SDL?

There are examples in the docs and the directory “test”.

Bye,

Tim