Thread: Assertion Failure

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Assertion Failure

    Ok, so I'm learning Lesson 10 on First Person Movement on Nehe.gamedev.net OpenGLTutorials. I copied the code and pasted it. I've put down all of the libraries and checked all of the file connections. I get this assertion failure. I'll copy the error message as I see it:

    Code:
    Debug Assertion Failed! 
    
    Program: E:\Programs\...\OpenGL Tests\Test 6\Test 6\Debug\Test 6.exe 
    File: fgets.c 
    Line: 60 
    
    Expression: str !=NULL 
    
    For information on how your program can cause an assertion 
    failure, see the Visual C++ documentation on asserts.
    I hear there is a tool in MVC++ that I can use. What is it? If not, know of any other way to cure my program of this error? I have no idea...

  2. #2
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Ok!

    Alright, I found the debug program and I ran through it and it led to a line in the code that said

    Code:
    _ASSERTE(str != NULL);
    edit: this code snipit is from fgets.c
    What's wrong with it? What do I do about it?
    Last edited by drdroid; 01-03-2003 at 08:56 PM.

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    You're passing a NULL pointer to a function expecting a string, as far as I can see... It happens with ifstream/fstream when you supply it with a NULL pointer as the filename argument.

    Can we see the code?

  4. #4
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    code..

    heres the code:

  5. #5
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    I think you may need a bmp file to go along with it. So I guess I'll include that along too. This one came with the lesson on nehe.

  6. #6
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Modify your readstr() function to look like this:
    Code:
    void readstr(FILE *f,char *string)
    {
    if (string == NULL) { MessageBox(HWND_DESKTOP, "Ahem", "Error!", MB_OK|MB_ICONERROR); return; }
    	do
    	{
    		fgets(string, 255, f);
    	} while ((string[0] == '/') || (string[0] == '\n'));
    	return;
    }
    Then run your code and tell me if that Message comes up. Lets localize this problem, and since you said something about fgets, this seems like a likely culprit.

  7. #7
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    I still get teh error message.

  8. #8
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    Anybody else?

  9. #9
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    Should I ask this on another board? Windows, C++?

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Thanks for cross posting Next time, PM a mod if you want your thread moved.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  2. Debug Assertion failure problem
    By uldaman in forum C++ Programming
    Replies: 8
    Last Post: 01-21-2008, 02:22 AM
  3. delete Assertion Failure
    By cunnus88 in forum C++ Programming
    Replies: 8
    Last Post: 11-12-2005, 11:38 PM
  4. debug assertion failure
    By talz13 in forum Windows Programming
    Replies: 2
    Last Post: 07-20-2004, 11:23 AM
  5. Assertion failure while creating window
    By roktsyntst in forum Windows Programming
    Replies: 0
    Last Post: 02-10-2003, 08:18 PM