It is currently Thu Jul 27, 2017 1:33 pm




 Page 1 of 1 [ 3 posts ] 
Author Message
 Post subject: I get the Access violation error.
PostPosted: Sun Mar 22, 2009 6:33 pm 

Joined: Fri Nov 23, 2007 1:00 am
Posts: 52
Location: Your PC
I'm working on a Input field and for some reason I get the Access violation error when I run the PrintText line. Here is how I am using it:

m_pFontHandler.PrintTextA(10, (cy-300) / 2 ,(cx+100) / 2 , 256, 256, 256, 0.62f * multi, "Tag: %s", szGamerTag[MAX_GAMER_TAG_LENGTH]);



szGamerTag is a char type and yes I did use the memset for making the string null.

Whats inside PrintTextA
//If ID <= 0 ...

va_list ap;
   va_start(ap, szText);
   vsprintf(szTextOutput, szText, ap);
   va_end(ap);

   //m_VpFonts  ...


Thanks, I would appreciate your help for avoiding this Access Error.

-Andrew


Offline
 Profile  
 
 Post subject: I wish I knew
PostPosted: Mon Mar 23, 2009 12:42 pm 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
Well, please check that szTextOutput buffer has enough space. szText also must not be NULL (although your code suggests that szText = "Tag: %s").
Maybe something is wrong with szGamerTag[MAX_GAMER_TAG_LENGTH]), for instance the position [ MAX_GAMER_TAG_LENGTH ] might be right after the real end of your array or gamer tags. ;)

A hint.
I do prefer to use a form of vsprintf() that accepts explicit buffer-size value, for instance
void ErrorHandler::operator() (const TCHAR * msg, ...)
{
    if ( ! msg )
    {
        return;
    }

//  TCHAR m_errorMsg[ MSG_BUF_SIZE ];

    va_list ap;
    va_start ( ap, msg );
    _vsntprintf( m_errorMsg, MSG_BUF_SIZE, msg, ap ); // NOTE!
    va_end( ap );
   
    (...)
}


In other words instead of vsprintf() consider _vsntprintf(). The later will clip your string if it is longer than your buffer, but this is still less harmful, than the crash of your app in front of your most valuable customers.
:)


Offline
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 5:15 pm 

Joined: Fri Nov 23, 2007 1:00 am
Posts: 52
Location: Your PC
I got it working. I can't believe I was adding the array brackets. :x Thats why I was getting that error.

Thanks for the swift response, I appreciate it. :)


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 3 posts ] 


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