It is currently Fri May 26, 2017 2:01 pm

All times are UTC - 5 hours




 Page 2 of 2 [ 36 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Mon Apr 19, 2010 4:39 pm 

Joined: Sun Apr 18, 2010 11:46 am
Posts: 8
I did the alt-enter method and that seemed to work. Thanks!

I do know that you have to manually move the files for them to actually change positions on the HD, but I must have forgotten to move them or something.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Thu Apr 14, 2011 10:43 pm 

Joined: Thu Apr 14, 2011 6:41 pm
Posts: 4
Hello Marek.

I've been really enjoying your tutorials so far. Thank you for making them available.
I'm kind of stuck at the moment trying to change the f_open to f_open_s. When I changed it and ran debug I don't
get any debugging errors but when I run it, I get a windows message saying "debug Assertion Failed (str != NULL)".
I've check the web to see if I could find a solution but nothing that can help me out.

This is what I did.
//create a new log file
   errno_t err;

   FILE *fp;
   err = fopen_s(&fp, m_szFilename, "wt");
   if (err != NULL) {
      char tmpbuf[128];

      //display the date and time
      _strdate_s(tmpbuf, 128);
      fprintf(fp, "Date(M/D/Y): %s ", tmpbuf);
      _strtime_s(tmpbuf, 128);
      fprintf(fp, "%s\n\n", tmpbuf);
      fclose(fp);
   }


Any help would be great.
Thanks

ic2dcom
p.s. I'm using VC++ 2010


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Fri Apr 15, 2011 5:14 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
You have a logic problem with your code. What you are telling the computer to do is the following:

* try to open a file
* if I CAN'T open the file then write to it the date and time

Have a read through here, and pay specific attention to what the return value from fopen_s represents:
http://msdn.microsoft.com/en-us/library/z5​hh6ee9


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Sun Apr 17, 2011 10:53 pm 

Joined: Thu Apr 14, 2011 6:41 pm
Posts: 4
Thanks Marek

I got it. :)
I got a little confused by the fopen return value. I notice that the return value on the fopen is the opposite of fopen_s.

ic2dcom


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Thu Apr 16, 2015 1:54 am 

Joined: Sun Nov 23, 2014 2:38 am
Posts: 6
Thanks for the tutorials. I've found them very informative.

As with many others, I've been trying to update the code using functions Microsoft has deemed "safe". In this case, I am updating to the use of sprintf_s. Up to this point, I've had no difficulty until I got to this section:

// Name: DisplayFPSinTitle(:)
// Desc: Display the FPS in the titlebar of the window
//       NOTE: we are only using this as a temp solution to display FPS
//            until the font engine is built.
//
bool GameOGL::DisplayFPSinTitle()
{
   char szFPS[20];
   sprintf_s(szFPS, "%2.0f FPS", m_fps);

   char* szTitle = new char[strlen(m_pszTitle) + 24]; // little extra memory just to be safe
//   sprintf(szTitle, "%s%s", m_pszTitle, szFPS);
   sprintf_s(szTitle, sizeof(szTitle), "%s%s", m_pszTitle, szFPS);
   SetWindowText(m_hWnd, szTitle);
   delete[] szTitle;
   
   return true;
} // DisplayFPSinTitle

This code compiles without error. However, when run it generates a "Debug Assertion Failed!" error.

The full error is (I'm using MarekKnowsEngine instead of GameEngine):

    Microsoft Visual C++ Runtime Library

    Debug Assertion Failed!

    Program:
    ...nowsEngine\_Debug\Win32\MarekKnowsEngine.exe
    File: f:\\dd\vctools\crt\crtw32\stdio\vsprintf.c
    Line: 244

    Expression: ("Buffer too small", 0)

    For information on how your program can cause an assertion failure, see the Visuall C++ documentation on asserts.

    (Press Retry to debug the application)

I've found posts on other sites where people are getting this error, but I have yet to find a solution. How can I fix this error?

I am running VS 2013 Ultimate for my IDE.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Thu Apr 16, 2015 4:36 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
Look at your first sprintf_s call and compare it to your second call to sprintf_s. What are you doing in the one that you are not doing in the other?


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Thu Apr 16, 2015 5:57 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
sprintf_s(szTitle, sizeof(szTitle), "%s%s", m_pszTitle, szFPS);


This line of code is failing with a Buffer too small message because you are trying to stuff more than 4 bytes into szTitle, but you told it that 4 bytes is the limit.

sizeof(szTitle) is going to return to you the size of the pointer named szTitle which is 4.
If you did sizeof( szFPS ) you would get 20, since szFPS is an array.

So to fix the error, you probably want to do something like this:

int titleLength = strlen(m_pszTitle) + 24; // little extra memory just to be safe
char* szTitle = new char[ titleLength ];
sprintf_s(szTitle, titleLength, "%s%s", m_pszTitle, szFPS);


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Thu Apr 16, 2015 8:57 am 

Joined: Sun Nov 23, 2014 2:38 am
Posts: 6
Yup. That fixed it. Thanks!


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Thu Apr 16, 2015 9:01 am 

Joined: Sun Nov 23, 2014 2:38 am
Posts: 6
skilz80 wrote:
Look at your first sprintf_s call and compare it to your second call to sprintf_s. What are you doing in the one that you are not doing in the other?


If I were to take the original code:
sprintf(szTitle, "%s%s", m_pszTitle, szFPS);


and simply substitute sprintf_s in place of sprintf like so:
sprintf_s(szTitle, "%s%s", m_pszTitle, szFPS);


It won't even compile. When you F1 sprintf_s in the IDE, you discover that sprintf and sprintf_s are not identical. That is why you see a difference.

Edit: I should note that the reason you see a difference between the first sprintf_s and the one that was giving me the trouble has to do with the concatenation: "%s%s" portion of the code. that is why you have to use a different approach with sprintf and sprintf_s. Sprintf_s is more secure in that it is preventing you from assigning values greater than the memory allocated...which is essentially what was going wrong with my code before. It compiled fine, but the problem with the memory allocation wasn't revealed until runtime. I just didn't understand what was causing the problem until Marek gave me his example (Thanks again!)


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Wed Jun 22, 2016 9:41 pm 

Joined: Wed Jun 22, 2016 12:57 am
Posts: 1
Howdy! Had a question about ErrorHandler...

Whenever I try to compile in VS 2015 Community, I continually get a cannot open source file "stdafx.h".

I thought it was my precompiled headers setting in properties.

My main.cpp is set to create (/Yc)
My stdafx.cpp is set to Use (/Yu)
My ErrorHandler.cpp is set to Use (/Yu)
The project itself is also set to Use (/Yu)

I've tried setting the stdafx.cpp to create, but it didn't work.

Not sure what to do besides start over.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 2 - Error Handler class
PostPosted: Sun Aug 21, 2016 1:21 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
Right Click on your project within your solution from Solution Explorer and under C++ -> Precompiled Headers Select Use(/Yu) then hit apply. Next select the actual file stdafx.cpp with the property page still open and on this file only under C++ -> Precompiled Headers select Create(/Yc) then hit apply and okay. Make sure all *.cpp files within this project has "stdafx.h" included as the first include file; then do a clean build of your solution. After the clean build; compile your stdafx.cpp file and once it finishes compiling then do a build of your solution. If for some reason you still get errors; you may have to delete and remove both stdafx.h and stdafx.cpp from the solution explorer and add new files adding both of these to your source file directory. If you have to add these in brand new make sure you set the properties page for stdafx.h to Use(/Yu) and stdafx.cpp to Create (/Yc).


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 2 of 2 [ 36 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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

Jump to:  

cron