Hello,
I am developing a GPS-synthetic vision program for pocket PC.
At the present experimental stage, the landscape is flat, with just a few objects in 3D.
Once a second, the screen is erased and a new picture is drawn.
My problem is that after some 2000 - 6000 seconds, the graphics stops functioning. The picture becomes black-white, and clearing the screen stops functioning.
So using the program in flights, I have to stop the program every half an hour and start it again.
Anyone has an idea on how to fix the problem?
My first thought was that some variable dimension was too small. This has turned out not to be the case.
So now, I guess that some resource is not properly deleted.
One (less good) solution would be to automatically quit (or reset) the program and restart it at regular intervals. Quitting is easy enough, but how can I make it start again automatically?
In the lines below, I will describe the most important functions used for drawing.
The program draws in the main window. Before drawing anything (first time), I call the function
void Open_screen( HDC *win, HWND hwndDlg )
{
RECT bit_map;
Textposx = 1;
Textposy = 28;
Textlength = 10;
Textsize = 10;
Window = win;
BM_window = hwndDlg;
GetClientRect( BM_window, &bit_map);
Winheight = bit_map.bottom + 1;
Winwidth = bit_map.right + 1;
Pencil = CreatePen(PS_SOLID, 2, RGB( 0, 0, 0 ) ); // BLACK
Eraser = CreateSolidBrush( 0x00FFFFFF ); // WHITE
Paintbrush = CreateSolidBrush( 0x00000000 ); // BLACK
SelectObject(*Window, Pencil);
SetROP2(*Window, R2_MASKPEN);
}
To select the current color, I use the function Set_color. Is anything missing in that function?
void Set_color( int red, int green, int blue )
{
DeleteObject( Pencil );
DeleteObject( Paintbrush );
Pencil = CreatePen( PS_SOLID, 2, RGB( red, green, blue ) );
Paintbrush = CreateSolidBrush( Rgb( red, green, blue ) );
SelectObject(*Window, Pencil);
PixColor.red = red;
PixColor.green = green;
PixColor.blue = blue;
SetROP2( *Window, R2_COPYPEN );
}
Lines are drawn by the functions Move_to and Line_to
void Move_to( float x, float y)
{
X_win = Transform_x( x );
Y_win = Transform_y( y );
MoveToEx( *Window, X_win, Y_win, (LPPOINT) NULL);
Textposx = X_win;
Textposy = Y_win;
}
void Line_to( float x, float y)
{
X_win = Transform_x( x );
Y_win = Transform_y( y );
LineTo( *Window, X_win, Y_win );
}
The Transform functions make transformations from real world coordinates to screen coordinates, X_win and Y_win, that are integers.
Text is written by the function
void Prints( WCHAR *text )
{
Mkstring( text );
ExtTextOut( *Window, Textposx, Textposy, 0, NULL, String, Textlength, NULL);
Textposy += 12;
}
The Move_to function sets text position as well, so text comes at the object described.
Drawing sky and ground (and erasing previous picture) is performed by the following lines
Set_color( SKYBLUE );
FillRect( windDC, &Sky, Paintbrush ); // Paint sky
Set_color( LIGHTGREEN );
FillRect( windDC, &Ground, Paintbrush ); // Paint ground
Trying to solve the problem, I have made a simulated version for PC. There is no GPS-signal involved. It is simulated as well. The program behaves similarly there. The program crash does not occur at any specified time, neither in PC or pocket-PC, but typically within the time interval mentioned above.
Anyone has a solution to the problem?
Allan