The third arg to ConvertANSIToUnicode() is the size of the output buffer
in bytes. In this case you should use sizeof(unicode).
This kind of code is the wrong pattern for VGUI2. It will perform really
badly (because of the expensive operations you are running every time
you paint) and makes your layout really fragile. A better model is to
use a label to contain the text you want to draw and use an event to
update text. The position, size and font the label uses should be
contained in a .res file that is loaded by the base frame that owns the
label ( it looks like CBBHudTaskList should be a frame in your case).
If you cannot implement an event driven method then at least use the
::OnTick() method and only change the label text if the state changes.
You can use the ::SetText() label call to set the string to render, and
you don't need to do the unicode translation manually then.
- Alfred
Benjamin Davison wrote:
> --
> [ Picked text/plain from multipart/alternative ]
> Very weird indeed, I'm working on some VGUI code and for some reason
> it
> works in debug mode with the IDE attatched and fails to work in
> release
> mode, and for the life of me I am stumped for a soloution. Here is
> some code
> to see if you guys have run into this problem.
>
> void CBBHudTaskList::Paint( void )
> {
> // getting a pointer to the game rules
> CHL2MPRules *pRules = HL2MPRules();
> if ( !pRules )
> return;
> // local player
> C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
> if ( !pPlayer )
> return;
>
> string_t sString = "";
> wchar_t unicode[256];
>
> int x, y;
> int textSizeWide, textSizeTall;
> int iShown = 0; // number of lines shown
> int fontTall = vgui::surface()->GetFontTall( m_hLargeFont );
> int border = 20;
>
> x = border / 2; // ScreenWidth() - border - textSizeWide;
> y = iShown * fontTall; // border + iShown * fontTall;
>
> SetSize( 300 + border, 40 );
>
>
> if (pRules->m_bCaptureObjectActive == true)
> {
> sString = "Find the case!";
> }
> else if (pRules->m_bCaptureZoneActivated == true)
> {
> sString = "Get to this location and do something";
> }
> else
> {
> sString = "No mission selected!";
> }
>
> vgui::localize()->ConvertANSIToUnicode( sString, unicode, 256);
>
> // --- Set up default font and get character height for line
> spacing vgui::surface()->DrawSetTextFont( m_hLargeFont );
> //vgui::surface()->DrawSetTextFont( m_hLargeFont );
> vgui::surface()->DrawSetTextPos(x, y);
> vgui::surface()->DrawPrintText( unicode, wcslen(unicode) ); //
> print
> text
>
> BaseClass::Paint();
> }
>
> Now for some reason vgui::localize()->ConvertANSIToUnicode( sString,
> unicode, 256); was crashing the release mode(not the debug) if I put
> the
> buffer to 1024
>
> Have any of you guys run into this problem? Or can you see some error
> I have overlooked?
>
> --
> - Benjamin Davison
> --
>
> _______________________________________________
> To unsubscribe, edit your list preferences, or view the list
> archives, please visit:
> http://list.valvesoftware.com/mailman/listinfo/hlcoders
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders