D3DXGetImageInfoFromFile function
D3DXGetImageInfoFromFile function
本文关键字:function D3DXGetImageInfoFromFile 更新时间:2023-10-16
使用D3DXGetImageInfoFromFile()
函数给我这个:
Unhandled exception at 0x004114d4 in SAMPLE.exe: 0xC0000005: Access violation reading location 0x00000000.
// ...
WCHAR *Path = L"./LIFE.bmp";
D3DXIMAGE_INFO *Info;
IDirect3DSurface9 *Surface = NULL;
LPDIRECT3DDEVICE9 pd3dDevice;
// ...
D3DXGetImageInfoFromFile(Path, Info); // everything is fine here, unless i do the following:
pd3dDevice -> CreateOffscreenPlainSurface(Info->Width, Info->Height, Info->Format, D3DPOOL_SYSTEMMEM, &Surface, NULL);
那么,这里发生了什么?当我输入数字而不是Info->...
时,一切工作正常…
您传递未初始化的指针Info
,当方法试图访问您得到异常。您需要的是:
D3DXIMAGE_INFO Info;
D3DXGetImageInfoFromFile(Path, &Info);
pd3dDevice->CreateOffscreenPlainSurface(Info.Width, Info.Height, Info.Format, D3DPOOL_SYSTEMMEM, &Surface, NULL);
另外,我建议您处理返回HRESULT的任何函数的结果代码。如:
if (FAILED(D3DXGetImageInfoFromFile(Path, &Info))) {
// print something, abort or whatever.
}
如果您使用DXUT.h,那么V()
或V_RESULT
宏是您最好的朋友:
V(D3DXGetImageInfoFromFile(Path, &Info));
或
HRESULT hr;
V_RETURN(D3DXGetImageInfoFromFile(Path, &Info));
V_RETURN(pd3dDevice->CreateOffscreenPlainSurface(Info.Width, Info.Height, Info.Format, D3DPOOL_SYSTEMMEM, &Surface, NULL));
V_RETURN(...);
// ... lots of D3D calls.
return S_OK;
您可能需要转义到您的图像路径中的反斜杠:
std::wstring wsPath = L"C:\wood.bmp";
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- 库函数需要一个 std::function<void(void)>,如何传入类函数?
- Confusion: decltype vs std::function
- 为什么 std::function 可以作为 std::not2 的参数?
- 'max'匹配'std::function<const int &(const int &, const int &)>'无过载
- 传递给std::function template的template参数究竟代表什么
- 将带有unique_ptr的可变 lambda 传递给 const&std::function
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- "no matching function for call to 'Vector::Vector'"错误
- 如何在向量中删除 std::function<void()>?
- 不断"Attempting to reference a deleted function"
- 将函数包装器转换为 std::function
- 类型擦除的std::function与虚拟函数调用的开销
- C++ std::function 对于类 exept 的所有实例都是空的(只有 Visual2019 编译器问题)
- 如果模板没有可变参数,则 Lambda 被推导出为 std::function
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 模板规范获取'Ambiguous call to overloaded function'
- 将 lambda 表达式传递给 std::function in C++
- 为什么当我在 std::string 中打开文件名的 fstream 时出现"no matching function"错误?