Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: Lcc-Win32 Bug Report -- ATAN FUNCTION AGAIN!



Jacob -- In the following program, if I change:

#define PI atan (1)*4.0

to 

#define PI 3.14159 


the GPF in Win98/WinME goes away!

========================================
[EMAIL PROTECTED] (MrBCX) wrote in message 
> Jacob,
> 
> It took me a while to track this down.  The following program has
> compiled
> and run using Lcc-Win32 since 2001.  Sometime after July 2003, the
> program started GPF'ing at startup.
> 
> I discovered that if I substitute the <math.h> from the July 2003
> release of
> Lcc-Win32, the problem goes away.  I observed that you've done a lot
> of work
> in math.h since July 2003.
> 
> I haven't been able to track down the specific problem.  
> -------------------------------------------------------
> 
> #include <conio.h>
> #include <math.h>   // The July 2003 <math.h> allows this demo to run 
> #include <stdio.h>
> 
> // ***********
> //  Constants
> // ***********
> 
> #define AppName "Globe"
> #define Caption "Globe of Points"
> #define RADIUS 80
> #define SCALE 50
> #define SLICES 12
> #define PPS 20
> #define PI atan (1)*4.0
> #define myRED RGB (255,0,0)
> #define myGRN RGB (0,255,0)
> #define myBLU RGB (0,0,255)
> 
> 
> // ******************
> //  Types And Unions
> // ******************
> 
> 
> typedef struct _Point3D
> {
>   int  x;
>   int  y;
>   int  z;
> }Point3D, *LPPOINT3D;
> 
> 
> // ***********
> //  Variables
> // ***********
> 
> char    CRLF[3]={13,10,0};
> char    BCX_STR [1024*1024];
> 
> // ***********
> //  Variables
> // ***********
> 
> static int     XAngle;
> static int     YAngle;
> static int     ZAngle;
> static int     Distance;
> static int     Dir;
> static int     cxClient;
> static int     cyClient;
> static int     maxX;
> static int     maxY;
> static HDC     memdc;
> static HBITMAP hbit;
> static HRGN    Region;
> static Point3D Points[SLICES][PPS];
> static Point3D Ball[SLICES][PPS];
> static int     SinTable[256];
> static int     CosTable[256];
> 
> // ********
> //  Macros
> // ********
> 
> #define BOR |
> #define Show(Window)ShowWindow(Window,SW_SHOW);
> 
> 
> // ************
> //  Prototypes
> // ************
> 
> 
> int       WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
> LRESULT   CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
> void      DrawGlobe (HWND);
> void      DrawPoints (HWND);
> void      Rotate (void);
> void      SetupBall (void);
> void      RoundedEdge (HWND, int, int, int, int);
> void      Center (HWND);
> char*     BCX_TmpStr(size_t);
> 
> 
> 
> char *BCX_TmpStr (size_t Bites)
> {
>   static int   StrCnt;
>   static char *StrFunc[2048];
>   StrCnt=(StrCnt + 1) & 2047;
>   if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);
>   return StrFunc[StrCnt]=(char*)calloc(Bites+128,1);
> }
> 
> 
> 
> 
> void Center (HWND hWnd)
> {
>   RECT  DesktopArea;
>   RECT  rc;
>   SystemParametersInfo(SPI_GETWORKAREA,0,&DesktopArea,0);
>   GetWindowRect(hWnd,&rc);
>   SetWindowPos(hWnd,HWND_TOP,
>   ((DesktopArea.right-DesktopArea.left)-(rc.right-rc.left))/2+
>   DesktopArea.left,((DesktopArea.bottom-DesktopArea.top)-
>   (rc.bottom-rc.top))/2+DesktopArea.top,0,0,SWP_NOSIZE);
> }
> 
> 
> 
> 
> int WINAPI WinMain
> (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int CmdShow)
>   {
>     static  HWND  hWnd;
>     memset(&hWnd,0,sizeof(hWnd));
>     static  MSG  Msg;
>     memset(&Msg,0,sizeof(Msg));
>     static  WNDCLASSEX  wc;
>     memset(&wc,0,sizeof(wc));
>     wc.cbSize=sizeof(wc);
>     wc.style=CS_HREDRAW BOR CS_VREDRAW;
>     wc.lpfnWndProc=WndProc;
>     wc.cbClsExtra=0;
>     wc.cbWndExtra=0;
>     wc.hInstance=hInst;
>     wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
>     wc.hCursor=LoadCursor(NULL,IDC_ARROW);
>     wc.hbrBackground=GetStockObject(BLACK_BRUSH);
>     wc.lpszMenuName=NULL;
>     wc.lpszClassName=AppName;
>     wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
>     wc.lpszMenuName=NULL;
>     RegisterClassEx(&wc);
>     hWnd=CreateWindow
>     (AppName,Caption,WS_POPUP,0,0,400,350,NULL,(HMENU)NULL,hInst,NULL);
>     RoundedEdge(hWnd,400,350,300,300);
>     Center(hWnd);
>     Show(hWnd);
>     while(TRUE)
>       {
>         if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
>           {
>             if(Msg.message==WM_QUIT)
>               {
>                 break;
>               }
>             TranslateMessage(&Msg);
>             DispatchMessage(&Msg);
>           }
>         else
>           {
>             DrawGlobe(hWnd);
>           }
>       }
>     return Msg.wParam;
>   }
> 
> 
> 
> 
> LRESULT CALLBACK WndProc
> (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
> {
>   static  HDC  hdc;
>   memset(&hdc,0,sizeof(hdc));
>   static  PAINTSTRUCT  ps;
>   memset(&ps,0,sizeof(ps));
>   static int      loop;
>   memset(&loop,0,sizeof(loop));
>   while(1)
>   {
>   if(Msg==WM_CREATE)
>     {
>       maxX=GetSystemMetrics(SM_CXSCREEN);
>       maxY=GetSystemMetrics(SM_CYSCREEN);
>       hdc=GetDC(hWnd);
>       memdc=CreateCompatibleDC(hdc);
>       hbit=CreateCompatibleBitmap(hdc,maxX,maxY);
>       SelectObject(memdc,hbit);
>       SelectObject(memdc,GetStockObject(BLACK_BRUSH));
>       PatBlt(memdc,0,0,maxX,maxY,PATCOPY);
>       for(loop=0; loop<=255; loop+=1)
>         {
>           SinTable[loop]=(sin(PI*2/255*loop)*128);
>           CosTable[loop]=(cos(PI*2/255*loop)*128);
>         }
>       Distance=100;
>       Dir=-3;
>       SetupBall();
>       XAngle=0;
>       YAngle=0;
>       ZAngle=0;
>       return 0;
>       break;
>     }
>   if(Msg==WM_CHAR)
>     {
>       PostQuitMessage(0);
>       return 0;
>       break;
>     }
>   if(Msg==WM_NCHITTEST)
>     {
>       static  LRESULT  r;
>       memset(&r,0,sizeof(r));
>       r=DefWindowProc(hWnd,Msg,wParam,lParam);
>       if(r==HTCLIENT)
>         {
>           r=HTCAPTION;
>         }
>       return r;
>       break;
>     }
>   if(Msg==WM_SIZE)
>     {
>       cxClient=LOWORD(lParam);
>       cyClient=HIWORD(lParam);
>       SelectObject(memdc,GetStockObject(BLACK_BRUSH));
>       PatBlt(memdc,0,0,maxX,maxY,PATCOPY);
>       return 0;
>       break;
>     }
>   if(Msg==WM_PAINT)
>     {
>       hdc=BeginPaint(hWnd,&ps);
>       BitBlt(hdc,0,0,maxX,maxY,memdc,0,0,SRCCOPY);
>       EndPaint(hWnd,&ps);
>       return 0;
>       break;
>     }
>   if(Msg==WM_DESTROY)
>     {
>       DeleteObject(Region);
>       PostQuitMessage(0);
>       return 0;
>     }
>  break;
>   }
>  return DefWindowProc(hWnd, Msg, wParam, lParam);
> }
> 
> 
> 
> 
> void DrawGlobe (HWND hWnd)
> {
>   if(cxClient==0||cyClient==0)
>     {
>       return;
>     }
>   Sleep(1);
>   Rotate();
>   DrawPoints(hWnd);
>   XAngle+=3;
>   YAngle+=2;
>   ZAngle+=1;
>   Distance+=Dir;
>   if(XAngle>250)
>     {
>       XAngle=0;
>     }
>   if(YAngle>250)
>     {
>       YAngle=0;
>     }
>   if(ZAngle>250)
>     {
>       ZAngle=0;
>     }
>   if(Distance>=100)
>     {
>       Dir=-1;
>     }
>   if(Distance<=20)
>     {
>       Dir=1;
>     }
>  InvalidateRect(hWnd,NULL,0);
> }
> 
> 
> 
> 
> 
> void DrawPoints (HWND hWnd)
> {
>   static int      i;
>   memset(&i,0,sizeof(i));
>   static int      i2;
>   memset(&i2,0,sizeof(i2));
>   static int      Kolor;
>   //  Clear memdc to all black before plotting new points
>   SelectObject(memdc,GetStockObject(BLACK_BRUSH));
>   PatBlt(memdc,0,0,maxX,maxY,PATCOPY);
>   Kolor++;
>   if(Kolor>600)
>     {
>       Kolor=0;
>     }
>   for(i=0; i<=SLICES-1; i+=1)
>     {
>       for(i2=0; i2<=PPS-1; i2+=1)
>         {
>           if(Points[i][i2].z>=0)
>             {
>               while(1)
>               {
>               if(Kolor<200)
>                 {
>                   SetPixel(memdc,Points[i][i2].x,Points[i][i2].y,myBLU);
>                   SetPixel(memdc,Points[i][i2].x+1,Points[i][i2].y,myBLU);
>                   SetPixel(memdc,Points[i][i2].x,Points[i][i2].y+1,myBLU);
>                   SetPixel(memdc,Points[i][i2].x+1,Points[i][i2].y+1,myBLU);
>                   break;
>                 }
>               if(Kolor<400)
>                 {
>                   SetPixel(memdc,Points[i][i2].x,Points[i][i2].y,myGRN);
>                   SetPixel(memdc,Points[i][i2].x+1,Points[i][i2].y,myGRN);
>                   SetPixel(memdc,Points[i][i2].x,Points[i][i2].y+1,myGRN);
>                   SetPixel(memdc,Points[i][i2].x+1,Points[i][i2].y+1,myGRN);
>                   break;
>                 }
>               if(Kolor<600)
>                 {
>                   SetPixel(memdc,Points[i][i2].x,Points[i][i2].y,myRED);
>                   SetPixel(memdc,Points[i][i2].x+1,Points[i][i2].y,myRED);
>                   SetPixel(memdc,Points[i][i2].x,Points[i][i2].y+1,myRED);
>                   SetPixel(memdc,Points[i][i2].x+1,Points[i][i2].y+1,myRED);
>                 }
>               break;
>               }
>           }
>       }
>   }
> }
> 
> 
> 
> 
> 
> void Rotate (void)
> {
>   static int      i;
>   memset(&i,0,sizeof(i));
>   static int      i2;
>   memset(&i2,0,sizeof(i2));
>   static int      TempX;
>   memset(&TempX,0,sizeof(TempX));
>   static int      TempY;
>   memset(&TempY,0,sizeof(TempY));
>   static int      TempZ;

>   memset(&TempZ,0,sizeof(TempZ));
>   static int      OldTempX;
>   memset(&OldTempX,0,sizeof(OldTempX));
>   for(i=0; i<=SLICES-1; i+=1)
>     {
>       for(i2=0; i2<=PPS-1; i2+=1)
>         {
>           TempY=(Ball[i][i2].y*CosTable[XAngle]-Ball[i][i2].z*SinTable[XAngle])/128;
>           TempZ=(Ball[i][i2].y*SinTable[XAngle]+Ball[i][i2].z*CosTable[XAngle])/128;
>           TempX=(Ball[i][i2].x*CosTable[YAngle]-TempZ*SinTable[YAngle])/128;
>           TempZ=(Ball[i][i2].x*SinTable[YAngle]+TempZ*CosTable[YAngle])/128;
>           OldTempX=TempX;
>           TempX=(TempX*CosTable[ZAngle]-TempY*SinTable[ZAngle])/128;
>           TempY=(OldTempX*SinTable[ZAngle]+TempY*CosTable[ZAngle])/128;
>           Points[i][i2].x=(TempX*SCALE)/Distance+cxClient/2;
>           Points[i][i2].y=(TempY*SCALE)/Distance+cyClient/2;
>           Points[i][i2].z=TempZ;
>         }
>     }
> }
> 
> 
> 
> 
> 
> 
> void SetupBall (void)
> {
>   static int      slice;
>   memset(&slice,0,sizeof(slice));
>   static int      point;
>   memset(&point,0,sizeof(point));
>   static  double  Phi;
>   memset(&Phi,0,sizeof(Phi));
>   static  double  Theta;
>   memset(&Theta,0,sizeof(Theta));
>   for(slice=0; slice<=SLICES-1; slice+=1)
>     {
>       Phi=PI/SLICES*slice;
>       for(point=0; point<=PPS-1; point+=1)
>         {
>           Theta=2*PI/PPS*point;
>           //  -------------------------------------------------
>           //  Convert Radius, Theta and Phi to x,y,z coords
>           //  -------------------------------------------------
>           Ball[slice][point].y=(RADIUS*sin(Phi)*cos(Theta));
>           Ball[slice][point].x=(RADIUS*sin(Phi)*sin(Theta));
>           Ball[slice][point].z=(RADIUS*cos(Phi));
>         }
>     }
> }
> 
> 
> 
> void RoundedEdge (HWND hWnd, int Width, int Height, int R1, int R2)
> {
>   Region=CreateRoundRectRgn(0,0,Width,Height,R1,R2);
>   SetWindowRgn(hWnd,Region,TRUE);
> }



<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.