DirectX dsutil.cpp error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Netwatcher
    New Member
    • Sep 2008
    • 58

    DirectX dsutil.cpp error

    I've been trying to compile a program, everything is going fine until i get this little error:
    Code:
    ------ Build started: Project: Play_Sound, Configuration: Debug Win32 ------
    Compiling...
    dsutil.cpp
    c:\documents and settings\###\my documents\visual studio 2008\projects\play_sound\play_sound\dsutil.cpp(686) : error C2065: 'i' : undeclared identifier
    c:\documents and settings\###\my documents\visual studio 2008\projects\play_sound\play_sound\dsutil.cpp(687) : error C2065: 'i' : undeclared identifier
    Build log was saved at "file://c:\Documents and Settings\###\My Documents\Visual Studio 2008\Projects\Play_Sound\Play_Sound\Debug\BuildLog.htm"
    Play_Sound - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    ]

    And the exact lines that have this problem are
    Code:
    LPDIRECTSOUNDBUFFER CSound::GetFreeBuffer()
    {
        if( m_apDSBuffer == NULL )
            return FALSE; 
    
        for( DWORD i=0; i<m_dwNumBuffers; i++ )
        {
            if( m_apDSBuffer[i] )
            {  
                DWORD dwStatus = 0;
                m_apDSBuffer[i]->GetStatus( &dwStatus );
                if ( ( dwStatus & DSBSTATUS_PLAYING ) == 0 )
                    break;
            }
        }
    
        if( i != m_dwNumBuffers )
            return m_apDSBuffer[ i ];
        else
            return m_apDSBuffer[ rand() % m_dwNumBuffers ];
    }
    the frustrating part is that it isn't my code...
    and it's too complicated for me to figure out, i was thinking it was something with the braces and the "i" not being a identified in the "if" statement, although the program worked when i changed their location, there was no sound :(

    kind regards,
    Netwatcher.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Change your lines #5 and #6 to this:

    Code:
    DWORD i;
    for( i=0; i<m_dwNumBuffers; i++ )
    kind regards,

    Jos

    Comment

    • Netwatcher
      New Member
      • Sep 2008
      • 58

      #3
      Well it did exactly what i did :p
      But! it helped me find the real bug...
      debugging is a nasty process!
      Thanks :D

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Netwatcher
        Well it did exactly what i did :p
        But! it helped me find the real bug...
        debugging is a nasty process!
        Thanks :D
        Better be prepared then because this was an easy compile time bug: when you define a variable in the header part of a for loop that variable only exists in the scope of the for header and body; outside of that scope that variable simply doesn't exist. Note that very old C++ compilers made the variable exist in the block part following the for loop body; that was just a silly decision and has been corrrected.

        kind regards,

        Jos

        Comment

        • Netwatcher
          New Member
          • Sep 2008
          • 58

          #5
          ("Beginning Game Programming, Second edition"-chapter 9)
          I take it back...
          I'm using IBM T42 Thinkpad with with default hardware & newest Audio Drive
          The program loads A-okay but no sound whatever what i do :( can it be that
          My Audio hardware is not compatible with the DXaudio(using dsutil.cpp/h) lib? (i CAN play wav files with normal audio players)

          Comment

          Working...