How can I get rid of the warning Reading invalid data from ...?

CDev-8220 220 Reputation points
2023-06-24T01:43:12.89+00:00

The warning occurs on this line

if (displayModes[i].Width == (unsigned int)screenW) {}


Here is the code.

   int count = 0;
    DXGI_MODE_DESC* displayModes = {};

    UINT numModes = 0;
    DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
    UINT flags = DXGI_ENUM_MODES_INTERLACED;

    hr =  pDXGIAdapter->EnumOutputs(0, &pDXGIOutput);
    if (SUCCEEDED(hr))
    {
        hr = pDXGIOutput->GetDisplayModeList(format, flags/*0*/, &numModes, nullptr);
        if (SUCCEEDED(hr))
        {
            displayModes = new DXGI_MODE_DESC[numModes];
            if (displayModes) 
            {
                hr = pDXGIOutput->GetDisplayModeList(
                    format, flags/*0*/, &numModes, displayModes);
                if (SUCCEEDED(hr)) 
                {
                    for (UINT i = 0; i < numModes; i++)
                    {
                        if (displayModes[i].Width == (unsigned int)screenW)
                        {
                            if (displayModes[i].Height == (unsigned int)screenH)
                            {
                                numerator = displayModes[i].RefreshRate.Numerator;
                                denominator = displayModes[i].RefreshRate.Denominator;
                            }
                        }
                    }
                }
            }
        }
    }

    delete[] displayModes;
    displayModes = 0;

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,730 questions
{count} votes

2 answers

Sort by: Most helpful
  1. 2023-06-25T00:36:38.8166667+00:00

    عن طريق فريق مساعدة ميكروسوفت

    0 comments No comments

  2. CDev-8220 220 Reputation points
    2023-06-25T00:37:47.8333333+00:00

    This clears the warnings.

    int count = 0;
        DXGI_MODE_DESC* displayModes = {};
    
        UINT numModes = 0;
        DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
        UINT flags = DXGI_ENUM_MODES_INTERLACED;
    
        hr =  pDXGIAdapter->EnumOutputs(0, &pDXGIOutput);
        if (SUCCEEDED(hr))
        {
            hr = pDXGIOutput->GetDisplayModeList(format, flags/*0*/, &numModes, nullptr);
            if (SUCCEEDED(hr))
            {
                displayModes = new DXGI_MODE_DESC[numModes];
                if (displayModes) 
                {
                    hr = pDXGIOutput->GetDisplayModeList(
                        format, flags/*0*/, &numModes, displayModes);
                    if (SUCCEEDED(hr)) 
                    {
                        //***************************
                        DXGI_MODE_DESC* dm[50] = {};
                        for (UINT d = 0; d < numModes; d++) {
                            dm[d] = &displayModes[d];
                        }
                        
                        for (UINT i = 0; i < numModes; i++)
                        {
                            //***************************
                            if (dm[i]->Width == (unsigned int)screenW) /*{}
                            if (displayModes[i].Width == (unsigned int)screenWidth)*/
                            {
                                //***************************
                                if (dm[i]->Height == (unsigned int)screenH) /*{}
                                if (displayModes[i].Height == (unsigned int)screenHeight)*/
                                {
                                    numerator = displayModes[i].RefreshRate.Numerator;
                                    denominator = displayModes[i].RefreshRate.Denominator;
                                }
                            }
                        }
                    }
                }
            }
        }
    
        delete[] displayModes;
        displayModes = 0;
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.