Windows XP 上的 Direct3D ID3DXFont->DrawText 崩溃
我正在尝试从文件加载字体,然后在 Direct3D 中使用它,它在我的 Windows 7 计算机上完美运行,但如果我在 XP SP2 计算机上尝试它,第一次调用 DrawText
将返回 0(意味着失败),第二次尝试将导致程序崩溃。
Windows XP 上的 Direct3D 中导入的字体是否有一些限制?有没有办法获得一些有用的错误代码,因为 DrawText
返回 0 本身并不是很有帮助。
作为参考,这是我的字体导入代码:
if (AddFontResourceEx("ttfFiles/tf2Build.ttf", FR_PRIVATE, 0) == 0) {
// Throw exception.
}
这是我创建 ID3DXFont
对象的方法(它也没有问题地返回):
HRESULT result = D3DXCreateFont(
d3dDevice_,
height,
0,
isBolded ? FW_BOLD : FW_NORMAL,
0,
false,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
DEFAULT_QUALITY,
FF_DONTCARE,
name.c_str(),
&d3dFont );
if ( FAILED( result ) ) {
// Throw exception.
}
编辑: 我设法让它发生在XP 中的调试器,出现了一个非常可怕的错误:
DirectFont.exe 中发生类型为“System.AccessViolationException”的未处理异常 附加信息:尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
这是堆栈跟踪:
usp10.dll!ClientData::GetOtlTable() + 0x35 字节
usp10.dll!otlResourceMgr::getOtlTable() + 0x7a 字节
usp10.dll!SubstituteOtlChars() + 0x1af 字节
usp10.dll!OtlShape() + 0x3c5 字节
D3DX9_43.dll!D3DXCore::CFont::DrawTextAW() + 0x5aa 字节 D3DX9_43.dll!D3DXCore::CFont::DrawTextA() + 0x26 字节
I'm trying to load a font from a file and then use it in Direct3D, and it works perfectly on my Windows 7 machine, but if I try it on an XP SP2 machine, the first call to DrawText
will return 0 (meaning it failed), and the second time it tries will cause the program to crash.
Are there some restrictions with imported fonts in Direct3D on Windows XP? Is there a way I can get some useful error code, since DrawText
returning 0 isn't very helpful on its own.
For reference, here's my font importing code:
if (AddFontResourceEx("ttfFiles/tf2Build.ttf", FR_PRIVATE, 0) == 0) {
// Throw exception.
}
And here's how I create the ID3DXFont
object (which also returns without a problem):
HRESULT result = D3DXCreateFont(
d3dDevice_,
height,
0,
isBolded ? FW_BOLD : FW_NORMAL,
0,
false,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
DEFAULT_QUALITY,
FF_DONTCARE,
name.c_str(),
&d3dFont );
if ( FAILED( result ) ) {
// Throw exception.
}
Edit: I managed to get it to occur under a debugger in XP, and here's the quite scary error that appears:
An unhandled exception of type 'System.AccessViolationException' occured in DirectFont.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
And here is the stack trace:
usp10.dll!ClientData::GetOtlTable() + 0x35 bytes
usp10.dll!otlResourceMgr::getOtlTable() + 0x7a bytes
usp10.dll!SubstituteOtlChars() + 0x1af bytes
usp10.dll!OtlShape() + 0x3c5 bytes
D3DX9_43.dll!D3DXCore::CFont::DrawTextAW() + 0x5aa bytes
D3DX9_43.dll!D3DXCore::CFont::DrawTextA() + 0x26 bytes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能出在绘图循环中,而不是初始化中。在drawtext 调用处放置一个断点,并在第二次调用时查找任何无效参数。
The problem is probably in the drawing loop, rather than the initialization. Place a breakpoint at the drawtext call, and look for any invalid parameters at the second call.