0

I successfully managed to get the display configuration using the NvAPI_DISP_GetDisplayConfig function three times in a row (as explained in another thread), and would now like to change the scaling option of one of my displays.

However even if I try not to change any setting (or just change the scaling option) and simply apply the retrieved pathInfo back, the NvAPI_DISP_SetDisplayConfig fails. Does someone have an idea why?

NvAPI_Status status = NVAPI_OK;
NvU32 deviceCount = 0;
NV_DISPLAYCONFIG_PATH_INFO_V2 *  pathInfo = NULL;

status = NvAPI_Initialize();

if (status == NVAPI_OK) {
status = NvAPI_DISP_GetDisplayConfig(&deviceCount, pathInfo);
if ((status == NVAPI_OK) && (deviceCount > 0)) {

    printf("\nFirst pass ok. \n");
    pathInfo = new NV_DISPLAYCONFIG_PATH_INFO_V2[deviceCount];

    for (int i = 0; i < deviceCount; i++)
    {
        pathInfo[i].targetInfo = 0;
        pathInfo[i].targetInfoCount = 0;
        pathInfo[i].version = NV_DISPLAYCONFIG_PATH_INFO_VER2;
        pathInfo[i].sourceModeInfo = 0;
        pathInfo[i].reserved = 0;
    }

    status = NvAPI_DISP_GetDisplayConfig(&deviceCount, pathInfo);

    if (status == NVAPI_OK) {

         printf("\nSecond pass ok. \n");
        for (int i = 0; i < deviceCount; i++)
        {
            pathInfo[i].sourceModeInfo = new NV_DISPLAYCONFIG_SOURCE_MODE_INFO_V1;
            pathInfo[i].sourceModeInfo->reserved = 0;
            pathInfo[i].targetInfo = new NV_DISPLAYCONFIG_PATH_TARGET_INFO_V2[pathInfo[i].targetInfoCount];
            for (int j = 0; j < pathInfo[i].targetInfoCount; j++) {
                pathInfo[i].targetInfo[j].details = new NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO_V1;
                            pathInfo[i].targetInfo[j].details->version = NV_DISPLAYCONFIG_PATH_ADVANCED_TARGET_INFO_VER1;
                pathInfo[i].targetInfo[j].details->reserved = 0;
            }
        }
    }

    status = NvAPI_DISP_GetDisplayConfig(&deviceCount, pathInfo);
    if (status == NVAPI_OK) {
          printf("\nThird pass ok. \n");
    }

      for (int i = 0; i < deviceCount; i++)
        { 
            for (int j = 0; j < pathInfo[i].targetInfoCount; j++) {
                switch(pathInfo[i].targetInfo[j].details->scaling)
                {
                case NV_SCALING_DEFAULT:
                    printf("Default");
                    break;
                case NV_SCALING_GPU_SCALING_TO_CLOSEST:
                    printf("GPU Scaling to closest");
                    break;
                case NV_SCALING_GPU_SCALING_TO_NATIVE :
                    printf("GPU scaling to native");
                    break;
                case NV_SCALING_GPU_SCANOUT_TO_NATIVE :
                    printf("Gpu scanout to native");
                    break;
                case NV_SCALING_GPU_SCALING_TO_ASPECT_SCANOUT_TO_NATIVE :
                    printf("GPU scaling to aspect scanout to native");
                    break;
                case NV_SCALING_GPU_SCALING_TO_ASPECT_SCANOUT_TO_CLOSEST :
                    printf("Gpu scaling to aspect scanout to closest");
                    break;
                case NV_SCALING_GPU_SCANOUT_TO_CLOSEST :
                    printf("Gpu scanout to closest");
                    break;
                case NV_SCALING_CUSTOMIZED :
                    printf("Scaling customized");
                default:
                    printf("Nothing");
                    break;
               }             
            }     
        }

    //FAILS !!!!!!!!!!
      status = NvAPI_DISP_SetDisplayConfig(deviceCount,pathInfo,NV_DISPLAYCONFIG_VALIDATE_ONLY  );
    }

}

Any help would be greatly apreciated, thank you very much!

2 Answers2

0

You just seem to mention that SetDisplayConfig fails... It may help to solve your problem knowing exactly whats wrong... Can you give the specific error: For example, this is taken from NVAPI programming documentation:

/*
This function is used to print to the command line a text message
describing the nvapi error and quits
*/
void PrintError(NvAPI_Status status)
{
    NvAPI_ShortString
    szDesc = {0};
    NvAPI_GetErrorMessage
    (status, szDesc);
    printf(" NVAPI error: %s\n", szDesc);
    exit(-1);
}
DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
efel
  • 1,054
  • 3
  • 14
  • 29
  • Not sure if this will help anyone solve this issue but I was able to run this code and on the SetDisplayConfig line it crashed on me. When debugging, the crash threw an exception that noted access violation at a certain address. This address seemed to match the pOSAdapter address in one of NV objects in PathInfo. – efel Jul 16 '13 at 20:54
0

It's because IsNonNVIDIAAdapter is set to true, but pOSAdapterID is not passed in. If you are sure you have a nVidia graphics card, do ZeroMemory() to pathInfo before use.

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
Hongyi
  • 1