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
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.
精彩评论