flat assembler
Message board for the users of flat assembler.

Index > Heap > What in the world......!?

Author
Thread Post new topic Reply to topic
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I was trying to shorten NeHe's OpenGL tutorial 6, the texturing one... and well... It worked, until i met the ifs. I found out i can take just about everything out of them (and did), but if i try to remove them, the box turns white. Keep them there, it's fine... Funny thing is, they do nothing. Infact, they don't even show up in the disassembly of a working program. But for some reson, it means all the difference of weather the program textures the cubes or not... Even though they're empty ifs and elses.

Code:
/*
 *                This Code Was Created By Jeff Molofee 2000
 *                A HUGE Thanks To Fredric Echols For Cleaning Up
 *           And Optimizing The Base Code, Making It More Flexible!
 *            If You've Found This Code Useful, Please Let Me Know.
 *            Visit My Site At nehe.gamedev.net
 */

#include <windows.h>              // Header File For Windows
#include <stdio.h>                  // Header File For Standard Input/Output
#include <gl\gl.h>                   // Header File For The OpenGL32 Library
#include <gl\glu.h>                   // Header File For The GLu32 Library
#include <gl\glaux.h>            // Header File For The Glaux Library

HDC                 hDC=NULL;               // Private GDI Device Context
HGLRC          hRC=NULL;               // Permanent Rendering Context
HWND          hWnd=NULL;              // Holds Our Window Handle
HINSTANCE hInstance;              // Holds The Instance Of The Application

bool    keys[256];                      // Array Used For The Keyboard Routine
bool  active=TRUE;            // Window Active Flag Set To TRUE By Default
bool    fullscreen=TRUE;        // Fullscreen Flag Set To Fullscreen Mode By Default

GLfloat     xrot;                           // X Rotation ( NEW )
GLfloat        yrot;                           // Y Rotation ( NEW )
GLfloat        zrot;                           // Z Rotation ( NEW )

GLuint     texture[1];                     // Storage For One Texture ( NEW )
HANDLE    hBMP=NULL;
BITMAP ImgInfo;

LRESULT    CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);   // Declaration For WndProc

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)           // Resize And Initialize The GL Window
{
    glViewport(0,0,width,height);                                           // Reset The Current Viewport

   glMatrixMode(GL_PROJECTION);                                            // Select The Projection Matrix
     glLoadIdentity();                                                                       // Reset The Projection Matrix

  // Calculate The Aspect Ratio Of The Window
 gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

       glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
      glLoadIdentity();                                                                       // Reset The Modelview Matrix
}

int InitGL(GLvoid)                                                                               // All Setup For OpenGL Goes Here
{
 glGenTextures(1, &texture[0]);
  hBMP=LoadImage(hInstance, "Data/NeHe.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
    GetObject(hBMP, sizeof(ImgInfo), &ImgInfo);
     glBindTexture(GL_TEXTURE_2D, texture[1]);
   glTexImage2D(GL_TEXTURE_2D, 0, 3, ImgInfo.bmWidth, ImgInfo.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, ImgInfo.bmBits);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

       glEnable(GL_TEXTURE_2D);                                                        // Enable Texture Mapping ( NEW )
   glShadeModel(GL_SMOOTH);                                                        // Enable Smooth Shading
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                           // Black Background
 glClearDepth(1.0f);                                                                     // Depth Buffer Setup
       glEnable(GL_DEPTH_TEST);                                                        // Enables Depth Testing
    glDepthFunc(GL_LEQUAL);                                                         // The Type Of Depth Testing To Do
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);      // Really Nice Perspective Calculations
     return TRUE;                                                                            // Initialization Went OK
}

int DrawGLScene(GLvoid)                                                                      // Here's Where We Do All The Drawing
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear The Screen And The Depth Buffer
    glLoadIdentity();                                                                       // Reset The View
   glTranslatef(0.0f,0.0f,-5.0f);

  glRotatef(xrot,1.0f,0.0f,0.0f);
     glRotatef(yrot,0.0f,1.0f,0.0f);
     glRotatef(zrot,0.0f,0.0f,1.0f);

 glBindTexture(GL_TEXTURE_2D, texture[0]);

       glBegin(GL_QUADS);
          // Front Face
               glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
          glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
          // Back Face
                glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
          glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
          // Top Face
         glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
          glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
          glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
          // Bottom Face
              glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
          glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
          glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
          // Right face
               glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
          glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
          // Left Face
                glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
          glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
          glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
          glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
  glEnd();
    SwapBuffers(hDC);
   xrot+=0.3f;
 yrot+=0.2f;
 zrot+=0.4f;
 return TRUE;
}

/*        This Code Creates Our OpenGL Window.  Parameters Are:                                       *
 * title                   - Title To Appear At The Top Of The Window                              *
 * width                   - Width Of The GL Window Or Fullscreen Mode                             *
 * height                  - Height Of The GL Window Or Fullscreen Mode                    *
 * bits                    - Number Of Bits To Use For Color (8/16/24/32)                  *
 * fullscreenflag  - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)   */
 
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
 GLuint          PixelFormat;                    // Holds The Results After Searching For A Match
    WNDCLASS        wc;                                             // Windows Class Structure
  DWORD           dwExStyle;                              // Window Extended Style
    DWORD           dwStyle;                                // Window Style
     RECT            WindowRect;                             // Grabs Rectangle Upper Left / Lower Right Values
  WindowRect.left=(long)0;                        // Set Left Value To 0
      WindowRect.right=(long)width;           // Set Right Value To Requested Width
       WindowRect.top=(long)0;                         // Set Top Value To 0
       WindowRect.bottom=(long)height;         // Set Bottom Value To Requested Height

 fullscreen=fullscreenflag;                      // Set The Global Fullscreen Flag

       hInstance                       = GetModuleHandle(NULL);                                // Grab An Instance For Our Window
  wc.style                        = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;   // Redraw On Size, And Own DC For Window.
   wc.lpfnWndProc          = (WNDPROC) WndProc;                                    // WndProc Handles Messages
 wc.cbClsExtra           = 0;                                                                    // No Extra Window Data
     wc.cbWndExtra           = 0;                                                                    // No Extra Window Data
     wc.hInstance            = hInstance;                                                    // Set The Instance
 wc.hIcon                        = LoadIcon(NULL, IDI_WINLOGO);                  // Load The Default Icon
    wc.hCursor                      = LoadCursor(NULL, IDC_ARROW);                  // Load The Arrow Pointer
   wc.hbrBackground        = NULL;                                                                 // No Background Required For GL
    wc.lpszMenuName         = NULL;                                                                 // We Don't Want A Menu
    wc.lpszClassName        = "OpenGL";                                                           // Set The Class Name

   /* WTF!? */
 if (0)                                                  
    {                                                          
    }
      if (0)  
    {
              if (0)
              {
                      if (0)
                      {
                      }
                      else
                        {
                      }
              }
      }
      if (0)
      {                                                          
    }
      else
        {                                                  
    }
      if (0)  
    {
      }

  RegisterClass(&wc);
     dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
       dwStyle=WS_OVERLAPPEDWINDOW;
        AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); 

        hWnd=CreateWindowEx(        dwExStyle,                                              
                                                            "OpenGL",                                             
                                                            title,                                                  
                                                            dwStyle |                                               
                                                            WS_CLIPSIBLINGS |                               
                                                            WS_CLIPCHILDREN,                                
                                                            0, 0,                                                           
                                                            WindowRect.right-WindowRect.left,       
                                                            WindowRect.bottom-WindowRect.top,       
                                                            NULL,                                                           
                                                            NULL,                                                           
                                                            hInstance,                                              
                                                            NULL);

      static  PIXELFORMATDESCRIPTOR pfd=                      
    {
              sizeof(PIXELFORMATDESCRIPTOR),          
            1,                                                                              
            PFD_DRAW_TO_WINDOW |                                    
            PFD_SUPPORT_OPENGL |                                    
            PFD_DOUBLEBUFFER,                                                       
            PFD_TYPE_RGBA,                                                  
            bits,                                                                   
            0, 0, 0, 0, 0, 0,                                               
            0,                                                                              
            0,                                                                              
            0,                                                                              
            0, 0, 0, 0,                                                     
            16,                                                                              
           0,                                                                              
            0,                                                                              
            PFD_MAIN_PLANE,                                                 
            0,                                                                              
            0, 0, 0                                                                 
    };
     
    hDC=GetDC(hWnd);                                
    PixelFormat=ChoosePixelFormat(hDC,&pfd);
        SetPixelFormat(hDC,PixelFormat,&pfd);
   hRC=wglCreateContext(hDC);
  wglMakeCurrent(hDC,hRC);
    ShowWindow(hWnd,SW_SHOW);                       
    SetForegroundWindow(hWnd);                                      
    SetFocus(hWnd);                                                                 
    ReSizeGLScene(width, height);                   
    InitGL();
   return TRUE;    
}

LRESULT CALLBACK WndProc( HWND    hWnd,                   
                                                    UINT    uMsg,                   
                                                    WPARAM  wParam, 
                                                    LPARAM  lParam)                     
{
  if (uMsg==WM_CLOSE) {
          PostQuitMessage(0);     
            return 0; }
    else if (uMsg==WM_SIZE){
               ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
                       return 0; }
    return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain( HINSTANCE       hInstance,                      
                                    HINSTANCE       hPrevInstance,          
                                    LPSTR           lpCmdLine,              
                                    int                     nCmdShow)           
{
  MSG             msg;                                                            
    BOOL    done=FALSE;                                                     

        // Create Our OpenGL Window
 CreateGLWindow("NeHe's Texture Mapping Tutorial",640,480,16,fullscreen);

     while(!done)                                                            
    {
              PeekMessage(&msg,NULL,0,0,PM_REMOVE);
                   if (msg.message==WM_QUIT)                       
                    {
                              done=TRUE;                                              
                    }
              TranslateMessage(&msg);                     
            DispatchMessage(&msg);                      
            DrawGLScene();

  }

  // Shutdown
 wglMakeCurrent(NULL,NULL);
  wglDeleteContext(hRC);
      ReleaseDC(hWnd,hDC);
        return (msg.wParam);                                                    // Exit The Program
}
    


For your amusement... I'm guessing it's a visual C++ 6.0 bug, but i'm posting it incase it works in future versions as well.
Post 16 Jun 2007, 10:00
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
if they don't show up in disassembly, then i can't imagine how could they affect this. why don't you compare resulting binaries?

by the way, code is missing error handling, as usual Wink
Post 16 Jun 2007, 10:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I tried using the error traps and they didn't help. I first removed the RegisterClass out, nothing bad happened, so i then took out the if... Turned white, and the error traps didn't catch anything. Basically, those ifs do a whole lot of nothing, which some how does something... And i'm about to compare them myself. This is turning into one interesting conversion.

Basically, i am removing the error traps because technically, once it works it works. It's not like i'm going to re-distribute the end result, so the code will be more GL for a referance back to later. I can add my own error checking as needed in non-referance projects. Though i've noticed that some people have a bad habit of getting error check happy. Sometimes people will actually error check if a file exists or not when they get the file path from a common dialog even when the path must exist flag is set. Anyway... The empty ifs are somehow helping the texturing... You're welcome to join my quest if you want. Aside from major differences in the exe, i really don't know what to look for cause i've never came accross something this wacky.

EDIT: Some how those ifs screwed up the alignments. Which helped it because i put a 1 when accessing an array where i should have put a 0. The screwed up alignment fixed that.
Post 16 Jun 2007, 10:26
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Basically, i am removing the error traps because technically, once it works it works.

i don't know your definition of "technicality", but no, once it works on your machine in specific configuration and state of computer, it doesn't mean it will work on every machine under any circumstances.


Quote:
It's not like i'm going to re-distribute the end result,

but you are showing it as example of OpenGL programming, aren't you? This isn't proper way of OpenGL programming

Quote:
Though i've noticed that some people have a bad habit of getting error check happy.

bad? You mean you find it "bad", or you can actually give some reason why it is bad?

Quote:
Sometimes people will actually error check if a file exists or not when they get the file path from a common dialog even when the path must exist flag is set.

think about it again... are you sure there is no way that file would exist while getting path, and not after that? and are you sure only thing that CreateFile can return is ERROR_FILE_NOT_FOUND?
Post 17 Jun 2007, 17:56
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Quote:
i don't know your definition of "technicality", but no, once it works on your machine in specific configuration and state of computer, it doesn't mean it will work on every machine under any circumstances.


That's the purpose of a beta test. Anyway, some things like CreateWindowEx when you're trying to use a class that your own program already successfully created. I find that some functions like that are going to work on your computer the same way as everyone else's unless they got some funky stuff wrong with it. Then people error trap the stuff at the end. Chances are, if it failed to close the the handles and stuff, there's nothing you can do about it anyway, except scare the person out of using your program.

Quote:
but you are showing it as example of OpenGL programming, aren't you? This isn't proper way of OpenGL programming


Notes to myself none the less. if i ever distributed i would warn people that error checking is better in a real world situation.

Quote:

bad? You mean you find it "bad", or you can actually give some reason why it is bad?


Too much error checking can get really messy when you're debugging. Especially if you run into the problems i usually run into where the return value says it's error free. Though in release versions, error check all you want. Heck, my last trouble was something error checkin' couldn't possibly have caught. I missed the spot that said normals, which'll be a pain in the tush in the long run it seems.

Quote:
think about it again... are you sure there is no way that file would exist while getting path, and not after that? and are you sure only thing that CreateFile can return is ERROR_FILE_NOT_FOUND?


That is either one quickly deleted file, or it is probably corrupted. And while handing out an empty screen for corrupted files really isn't really the "professional thing to do," it is, however, what the professions have a tendancy of doing from what i've seen.
Post 17 Jun 2007, 20:22
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
I find that some functions like that [CreateWindowEx] are going to work on your computer the same way as everyone else's unless they got some funky stuff wrong with it.

yes. and those "funky stuff" is exactly the reason of error handling. Another is catching of your own errors, in less trivial apps where nothing is obious.

Quote:
Then people error trap the stuff at the end. Chances are, if it failed to close the the handles and stuff, there's nothing you can do about it anyway, except scare the person out of using your program.

testing error on closing stuff is useful to catch bugs in code

Quote:
Notes to myself none the less. if i ever distributed i would warn people that error checking is better in a real world situation.

everything's okay then Wink

Quote:
Too much error checking can get really messy when you're debugging.

i would say opposite from my experiences

Quote:
Especially if you run into the problems i usually run into where the return value says it's error free.

It doesn't say it's error free. It only says no error was detected Wink

Quote:
Quote:
think about it again... are you sure there is no way that file would exist while getting path, and not after that? and are you sure only thing that CreateFile can return is ERROR_FILE_NOT_FOUND?

That is either one quickly deleted file, or it is probably corrupted. And while handing out an empty screen for corrupted files really isn't really the "professional thing to do," it is, however, what the professions have a tendancy of doing from what i've seen.

yes, that "quick deleting" is called race condition, for sure important thing to look about.

And there are many many more reasons why CreateFileEx can fail than just non-existing file and corruption. That is why you should always check for error, especially when you don't know all possible errors.
Post 17 Jun 2007, 20:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Quote:
yes. and those "funky stuff" is exactly the reason of error handling. Another is catching of your own errors, in less trivial apps where nothing is obious.


That's my problem... When the errors aren't obvious, the ret says no errors detected.

Quote:
testing error on closing stuff is useful to catch bugs in code


But in released versions? I like to consider the end of a program a bottle neck, sometimes. When your program apperas not to be responding to that X click, the first thing they do is head into task manager, then you have a leak on your hands.

Quote:
everything's okay then


Oh, of course. You should see all the error checks in phase 1 of kim... i might release it now since i'm thinking about starting the whole project from scratch.

Quote:
i would say opposite from my experiences


Unless you do what i do and set closely connected calls really close together then set the screens side by side with a working version. if you know where the error is, then you can do that.

Quote:
Ut doesn't say it's error free. It only says no error was detected


This is true.

Quote:
yes, that "quick deleting" is called race condition, for sure important thing to look about.


That is one quick deleting thing... Cause usually i get the file name with the common DLG and open that thing up pretty directly, which should lock it from bein' deleted. But i guess it is possible to delete the file in the transition period between closing the dialog and getting to the createfile...

Quote:
And there are many many more reasons why CreateFileEx can fail than just non-existing file and corruption. That is why you should always check for error, especially when you don't know all possible errors.


Perhaps it would be wise to get a list of error codes every once in a while.
Post 17 Jun 2007, 21:39
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
kohlrak wrote:
That's my problem... When the errors aren't obvious, the ret says no errors detected.

not always

Quote:
Oh, of course. You should see all the error checks in phase 1 of kim... i might release it now since i'm thinking about starting the whole project from scratch.

would be nice to see it

Quote:
That is one quick deleting thing... Cause usually i get the file name with the common DLG and open that thing up pretty directly, which should lock it from bein' deleted. But i guess it is possible to delete the file in the transition period between closing the dialog and getting to the createfile...

yup, that is one possible place to crash your app. And i believe that my app shouldn't crash in any case i am aware of.

Quote:
Quote:
And there are many many more reasons why CreateFileEx can fail than just non-existing file and corruption. That is why you should always check for error, especially when you don't know all possible errors.

Perhaps it would be wise to get a list of error codes every once in a while.

yes, but MS doesn't provide it (it would be harder than hell for them to maintain it)
Post 17 Jun 2007, 22:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Quote:
not always


I ment when i have problems. 9 out of every 10 of my problems, i've already looked at the ret values and ensured they don't go wrong beforehand.

Quote:
would be nice to see it


I don't know yet. Phase 1 of KIM is actually just a console app. I was reading mad wizard's stuff and i just coded as i went and put in alot of error checking. The code is messy and it's one of the first things i went for when i figured out how to do things in assembly. The code is so embarassing i might just delete it and pretend it never existed. Phase 1 was designed to be a partner program with quetannon (sp?), which was the fasm winsocks example.

Quote:
yes, but MS doesn't provide it (it would be harder than hell for them to maintain it)


Isn't that what getlasterr is for?
Post 17 Jun 2007, 23:03
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
I ment when i have problems. 9 out of every 10 of my problems, i've already looked at the ret values and ensured they don't go wrong beforehand.

that's true for me too. But that 1/10 is sometimes sooo fucking hard to find that it's worth of effort to check everything. And even worse, if problem doesn't appear while testing but later, message and clean exit is better than crash.

Quote:
Isn't that what getlasterr is for?

I was talking about complete list of possible errors that API func can return.
Post 17 Jun 2007, 23:23
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Quote:
that's true for me too. But that 1/10 is sometimes sooo fucking hard to find that it's worth of effort to check everything. And even worse, if problem doesn't appear while testing but later, message and clean exit is better than crash.


True...

Quote:
I was talking about complete list of possible errors that API func can return.


Isn't that usually in the return section of all documentations of functions? THough i will admit... it is a pain for msdn to keep track of things as it is. That place seriously needs cleaned up. Microsoft needs to put new DLLs and things on hold to clean up that place.
Post 17 Jun 2007, 23:29
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Isn't that usually in the return section of all documentations of functions?

Surely not in MSDN. I have seen this in some unix standards where there are about 30 error codes (not thousands like in MS).

There is a huge problem with maintenace such documentation: if you change possible errors for function, then description of all other functions that use it must be changed as well. And when function call lots of other functions, same error code can be returned for multiple quite different reasons. Thus it is really too much effor list all possible errors and their reasons, and mostly not worth of effort.
Post 17 Jun 2007, 23:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Change in documentation only what you change in the file it involves. If you change the MessageBoxA function, the return code change is only from the MessageBoxA function, not other functions. If another function called MessageBoxA, rather than adding a list of possible return codes to all the functions that call it, just put a link in that section that says that the function calls MessageBoxA, and that the return codes for that function may be returned.
Post 17 Jun 2007, 23:46
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
bionicalbat



Joined: 17 Jul 2007
Posts: 4
bionicalbat
Error - the program has generated an error and will now close. Would you like to submit the error to microsoft?
Do you think microsoft knows what the error code is, or *why* the program generated a protection fault at 0x4847373? Do you think microsoft knows who i am, and studies my error codes? Is there a database somewhere with my program in it and all my error codes?
Would you like [Details]? Windows closed the program it had loaded at 0x4847373, which has nothing to do with why the program closed.

Now .... Error code 0x576849 - programmer accidentally used a parenthasis in the wrong place.
Error code 0x576849 -Programmer was up late drinking and spilt beer on the keyboard. Wiping up, he accidentally clicked dyuhg'y and ctrl-s, which saved his code.
Would you like to submit this information to Microsoft? Microsoft doesn't care about you or anything, but they're dedicated in providing complexity, control, image, etc etc ....

No, error codes tell you where to look in your own programs for stuff. If you know what does what, you put error codes in to tell you later. AND you display error codes to other computer savvy people if they have any kind of control over what goes into the program. But Microsoft has the most ellaborate error code system in the world, and unless you program with C++.net professional edition with hacks, bells, whistles, etc .... it does nothing for you.
Post 17 Jul 2007, 07:03
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Change in documentation only what you change in the file it involves. If you change the MessageBoxA function, the return code change is only from the MessageBoxA function, not other functions.

haha...

That could work in one-man project, not in something as huge as microsoft. no chance. And even in one-man project it isn't always as easy, from my personal experiences...

bionicalbat:
1. Crash address is not same as error code
2. Microsoft DOES know what it's error code means, and so should you. It's on MSDN.
3. Microsoft DOES know where any address is within it's application code. They have tools that can parse lot of info dump, like call stack, or exact place in source.

Quote:
No, error codes tell you where to look in your own programs for stuff

Quote:
But Microsoft has the most ellaborate error code system in the world, and unless you program with C++.net professional edition with hacks, bells, whistles, etc .... it does nothing for you.

how about ERROR_FILE_NOT_FOUND returned by CreateFile? Oh, what the hack, if file isn't there, let's just crash... (and blame microsoft code for being buggy)
Post 17 Jul 2007, 09:04
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf
vid wrote:
how about ERROR_FILE_NOT_FOUND returned by CreateFile? Oh, what the hack, if file isn't there, let's just crash... (and blame microsoft code for being buggy)


Since when is proper error handling being implemented anywhere?

As I recall, having zero error handling often leads one's programs to be generally more reliable than with default error handling.

Take the Microsoft Exchange server... if it gets into a funny situation it just closes down. No whatchdog service, no error handling, it just closes. Forever. If you want your mail service to be reliable you have to have a guy sitting next to the server and restarting the service whenever it recieves confusing data off the net.

So far I haven't seen very many programs out there that had proper error handling; e.g.: the reaction you'd think is common sense when specific errors occur. It's either partially handled, like program kills itself, or it's not properly implemented at all.

No error handling on communications equipment is a death trap; take Ethernet switches: if they do not recieve an ending for an Ethernet packet due to some elecrical problem, they just wait for the ending forever and ever... untill you power-cycle the hardware. Take most other high-tech solutions where PC-to-hardware communication is present: if there is a communications error it just says Error and waits for user input or multi-taskingly creates an endless stream of simultaneous timeouts.

I'm guessing it must be something in the programming tools that prevents error handling from being done right.
Post 17 Jul 2007, 12:18
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger Reply with quote
m



Joined: 28 Dec 2006
Posts: 304
Location: in
m
This error checking stuff is scaring me Shocked

_________________
Attitude!
Post 18 Jul 2007, 05:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.