Fixed a memory leak (thanks for the correction, John!).

Smoothed over some code style issues while I was here, but left the
init-string parsing alone for now.


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@292 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-11-03 21:41:07 +00:00
parent 7c699fab2f
commit 9b257588e0

View File

@ -37,11 +37,13 @@
/* /*
* TODO BEFORE THE STABLE RELEASE: * TODO BEFORE THE STABLE RELEASE:
* *
* fgDeinitialize() -- Win32's OK, X11 needs the OS-specific deinitialization done * fgDeinitialize() -- Win32's OK, X11 needs the OS-specific
* deinitialization done
* glutInitDisplayString() -- display mode string parsing * glutInitDisplayString() -- display mode string parsing
* *
* Wouldn't it be cool to use gettext() for error messages? I just love bash saying * Wouldn't it be cool to use gettext() for error messages? I just love
* "nie znaleziono pliku" instead of "file not found" :) Is gettext easily portable? * bash saying "nie znaleziono pliku" instead of "file not found" :)
* Is gettext easily portable?
*/ */
/* -- GLOBAL VARIABLES ----------------------------------------------------- */ /* -- GLOBAL VARIABLES ----------------------------------------------------- */
@ -216,29 +218,29 @@ void fgDeinitialize( void )
/* /*
* If there was a menu created, destroy the rendering context * If there was a menu created, destroy the rendering context
*/ */
if ( fgStructure.MenuContext ) if( fgStructure.MenuContext )
{ {
free ( fgStructure.MenuContext ) ; free( fgStructure.MenuContext );
fgStructure.MenuContext = NULL ; fgStructure.MenuContext = NULL;
} }
fgDestroyStructure(); fgDestroyStructure();
while ( (timer = (SFG_Timer *)fgState.Timers.First) != NULL ) while( timer = (SFG_Timer *)fgState.Timers.First )
{ {
fgListRemove ( &fgState.Timers, &timer->Node ) ; fgListRemove ( &fgState.Timers, &timer->Node );
free ( timer ) ; free( timer );
} }
fgJoystickClose(); fgJoystickClose( );
fgState.Position.X = -1 ; fgState.Position.X = -1;
fgState.Position.Y = -1 ; fgState.Position.Y = -1;
fgState.Position.Use = FALSE ; fgState.Position.Use = FALSE;
fgState.Size.X = 300 ; fgState.Size.X = 300;
fgState.Size.Y = 300 ; fgState.Size.Y = 300;
fgState.Size.Use = TRUE ; fgState.Size.Use = TRUE;
fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH;
@ -258,26 +260,35 @@ void fgDeinitialize( void )
fgState.GameModeDepth = 16; fgState.GameModeDepth = 16;
fgState.GameModeRefresh = 72; fgState.GameModeRefresh = 72;
fgState.Time.Set = FALSE ; fgState.Time.Set = FALSE;
fgState.Timers.First = fgState.Timers.Last = NULL ; fgState.Timers.First = fgState.Timers.Last = NULL;
fgState.IdleCallback = NULL ; fgState.IdleCallback = NULL;
fgState.MenuStateCallback = (FGCBmenuState)NULL ; fgState.MenuStateCallback = (FGCBmenuState)NULL;
fgState.MenuStatusCallback = (FGCBmenuStatus)NULL ; fgState.MenuStatusCallback = (FGCBmenuStatus)NULL;
fgState.SwapCount = 0; fgState.SwapCount = 0;
fgState.SwapTime = 0; fgState.SwapTime = 0;
fgState.FPSInterval = 0; fgState.FPSInterval = 0;
if( fgState.ProgramName )
{
free( fgState.ProgramName );
fgState.ProgramName = NULL;
}
#if TARGET_HOST_UNIX_X11 #if TARGET_HOST_UNIX_X11
/* /*
* Make sure all X-client data we have created will be destroyed on display closing * Make sure all X-client data we have created will be destroyed on
* display closing
*/ */
XSetCloseDownMode( fgDisplay.Display, DestroyAll ); XSetCloseDownMode( fgDisplay.Display, DestroyAll );
/* /*
* Close the display connection, destroying all windows we have created so far * Close the display connection, destroying all windows we have
* created so far
*/ */
XCloseDisplay( fgDisplay.Display ); XCloseDisplay( fgDisplay.Display );
@ -317,22 +328,22 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
/* check if GLUT_FPS env var is set */ /* check if GLUT_FPS env var is set */
{ {
const char *fps = getenv ( "GLUT_FPS" ); const char *fps = getenv ( "GLUT_FPS" );
if ( fps ) if( fps )
{ {
sscanf ( fps, "%d", &fgState.FPSInterval ) ; sscanf( fps, "%d", &fgState.FPSInterval );
if ( fgState.FPSInterval <= 0 ) if( fgState.FPSInterval <= 0 )
fgState.FPSInterval = 5000 ; /* 5000 milliseconds */ fgState.FPSInterval = 5000; /* 5000 milliseconds */
} }
} }
#if TARGET_HOST_WIN32 #if TARGET_HOST_WIN32
if ( !getenv ( "DISPLAY" ) ) if( !getenv( "DISPLAY" ) )
displayName = strdup ( "" ) ; displayName = strdup( "" );
else else
#endif #endif
displayName = strdup( getenv( "DISPLAY" ) ); displayName = strdup( getenv( "DISPLAY" ) );
if (!displayName) if( !displayName )
fgError ("Could not allocate space for display name."); fgError ("Could not allocate space for display name.");
for( i=1; i<argc; i++ ) for( i=1; i<argc; i++ )
@ -478,7 +489,6 @@ void FGAPIENTRY glutInitWindowPosition( int x, int y )
{ {
if( (x >= 0) && (y >= 0) ) if( (x >= 0) && (y >= 0) )
{ {
fgState.Position.X = x; fgState.Position.X = x;
fgState.Position.Y = y; fgState.Position.Y = y;
fgState.Position.Use = TRUE; fgState.Position.Use = TRUE;