diff --git a/src/loaders/loader_nvml.cpp b/src/loaders/loader_nvml.cpp index 262b41a6..798e7452 100644 --- a/src/loaders/loader_nvml.cpp +++ b/src/loaders/loader_nvml.cpp @@ -161,6 +161,19 @@ bool libnvml_loader::Load(const std::string& library_name) { return false; } +#if defined(LIBRARY_LOADER_NVML_H_DLOPEN) + nvmlErrorString = + reinterpret_castnvmlErrorString)>( + dlsym(library_, "nvmlErrorString")); +#endif +#if defined(LIBRARY_LOADER_NVML_H_DT_NEEDED) + nvmlErrorString = &::nvmlErrorString; +#endif + if (!nvmlErrorString) { + CleanUp(true); + return false; + } + loaded_ = true; return true; } diff --git a/src/loaders/loader_nvml.h b/src/loaders/loader_nvml.h index dfb65d26..b42fd02c 100644 --- a/src/loaders/loader_nvml.h +++ b/src/loaders/loader_nvml.h @@ -31,6 +31,7 @@ class libnvml_loader { decltype(&::nvmlDeviceGetHandleByPciBusId_v2) nvmlDeviceGetHandleByPciBusId_v2; decltype(&::nvmlDeviceGetMemoryInfo) nvmlDeviceGetMemoryInfo; decltype(&::nvmlDeviceGetClockInfo) nvmlDeviceGetClockInfo; + decltype(&::nvmlErrorString) nvmlErrorString; private: void CleanUp(bool unload); diff --git a/src/nvml.cpp b/src/nvml.cpp index 95170bef..5819e061 100644 --- a/src/nvml.cpp +++ b/src/nvml.cpp @@ -22,10 +22,14 @@ bool checkNVML(const char* pciBusId){ ret = nvml.nvmlDeviceGetHandleByPciBusId(pciBusId, &nvidiaDevice); if (ret != NVML_SUCCESS) { - std::cerr << "MANGOHUD: Getting handle by PCI bus ID failed! Using index 0.\n"; + std::cerr << "MANGOHUD: Getting device handle by PCI bus ID failed: " << nvml.nvmlErrorString(ret) << "\n"; + std::cerr << " Using index 0.\n"; ret = nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice); } + if (ret != NVML_SUCCESS) + std::cerr << "MANGOHUD: Getting device handle failed: " << nvml.nvmlErrorString(ret) << "\n"; + nvmlSuccess = (ret == NVML_SUCCESS); return nvmlSuccess; }