Advertisement

Corrupted float ?

Started by November 22, 2000 04:28 AM
1 comment, last by Cygon 24 years, 2 months ago
I recently updated my DirectInput library from DX7 to DX8, also did some bug fixes and various addons. Well, the lib worked well before the update, and everything seemed to be normal after I was finished. In my lib, you can bind keys/buttons/axes to input functions, similar to Quake, later you can retrieve the state of any registered function using a function named GetState(). As soon as I began updating my examples a strange behavior occured: Althought, GetState() returned 1.0 when I pressed the Space bar (bound to ''PrimaryFire''), textout() just kept displaying 0.000. The functions involved are
  
 // ####################################################################### //

 // # CTFXInput::GetState()                                               # //

 // # Retrieves the status of an input function                           # //

 // ####################################################################### //

 float CTFXInput::GetState(char *p_pszName) {
   TFXHashString      l_CStr;
   CTFXInputFunction *l_pCFunction;
 
   if(!m_bEnabled)
     return 0.0f;
 
   l_CStr.Create(p_pszName, INPUTHASHSIZE);
   l_pCFunction = m_pCHash->Retrieve(&l_CStr);
 
   if(l_pCFunction)
     return l_pCFunction->m_fValue;
   else
     return 0.0f;
 }
 
 // ####################################################################### //

 // # TextOutf()                                                          # //

 // # Windows'' TextOut() with formatting like printf()                    # //

 // ####################################################################### //

 void TextOutf(HDC p_hDC, int p_nX, int p_nY, char *p_pszText, ...) {
   char    l_pszText[255];
   va_list l_CList;
 
   va_start(l_CList, p_pszText);
   vsprintf(l_pszText, p_pszText, l_CList);
   va_end(l_CList);
 
   TextOut(p_hDC, p_nX, p_nY, l_pszText, strlen(l_pszText));
 
   return;
 }
  
I have used the same TextOutf() in the DX7 version of my lib, where it worked! So I fear I''ve got some kind of memory leak or overwriting, but read on: This line correctly places the function values in my debug log TFXLOG("State of PrimaryFire: %.2f", m_pCInput->GetState("PrimaryFire")); while the TextOutf() always displays a 0.0 in my window TextOutf(l_hDC, 10, 50, "State of PrimaryFire: %.2f", m_pCInput->GetState("PrimaryFire")); I tried using a temporary float, eg. float l_fState; l_fState = m_pCInput->GetState("PrimaryFire"); TFXLOG("State of PrimaryFire: %.2f", l_fState); TextOutf(l_hDC, 10, 50, "State of PrimaryFire: %.2f", l_fState); Guess what ? TFXLOG() logs a 1.0 and TextOutf() shows a 0.0 What the heck is going on here ? Am I producing corrupted floats or what ? Help me before I go insane! -Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Oh, btw, anyone who wants to see for himself can download the sources at
www.LunaticSystems.de/data/TrueFX3b6x.zip 2,05MB

VisualC++ and DirectX 8 SDK required, of course.

-Markus-

Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Advertisement
Of course it happened what had to happen, just after posting I found out the error is another one:

Althought the Render() function is called frequently (as TFXLOG() proofs), the window content doesn''t get updated at all.
I have to drag another window around over my application to see any changes, and then windows still only updates the small area that needs to be redrawn, nothing more.

I thought it is (it was!) enough to call a function like this as often as possible when the application is in foreground, but althought the function executes, the window contents are stuck:
   // ####################################################################### // // # CTFXInputEx::Render()                                               # // // # Update the screen content                                           # // // ####################################################################### // void CTFXInputEx::Render(void) {   PAINTSTRUCT l_ps;   HDC         l_hDC;    m_nFrame++;    // Normal GDI-way to draw some text...   l_hDC = BeginPaint(GetWindow(), &l_ps);    SetTextColor(l_hDC, RGB(0, 255, 0));   SetBkMode(l_hDC, TRANSPARENT);    TextOutf(l_hDC, 10, 10, "TrueFX InputLib test. Frame %i. Press Esc to Quit", m_nFrame);    TextOutf(l_hDC, 10, 50, "State of PrimaryFire: %f", m_fPrimaryFire);   TextOutf(l_hDC, 10, 65, "State of SecondaryFire: %f", m_fSecondaryFire);   TextOutf(l_hDC, 10, 80, "State of TertiaryFire: %f", m_fTertiaryFire);    EndPaint(GetWindow(), &l_ps);    return; }  


I tried adding UpdateWindow() and such, but nothing changed.
Still an error in my lib, or is there just something missing in my Render() function ?

-Markus-

Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.

This topic is closed to new replies.

Advertisement