首先,这个项目不是我自己做的,我是从github上拿来的:
当我尝试使用任何directx11游戏时,就会出现这个问题。异常发生在DXHookD3D11.cs中
#region Draw overlay (after screenshot so we don't capture overlay as well)
if (this.Config.ShowOverlay)
{
// Initialise Overlay Engine
if (_swapChainPointer != swapChain.NativePointer || _overlayEngine == null)
{
if (_overlayEngine != null)
_overlayEngine.Dispose();
_overlayEngine = new DX11.DXOverlayEngine();
_overlayEngine.Overlays.Add(new Capture.Hook.Common.Overlay
{
Elements =
{
//new Capture.Hook.Common.TextElement(new System.Drawing.Font("Times New Roman", 22)) { Text = "Test", Location = new System.Drawing.Point(200, 200), Color = System.Drawing.Color.Yellow, AntiAliased = false},
new Capture.Hook.Common.FramesPerSecond(new System.Drawing.Font("Arial", 16)) { Location = new System.Drawing.Point(5,5), Color = System.Drawing.Color.Red, AntiAliased = true }
}
});
_overlayEngine.Initialise(swapChain);
_swapChainPointer = swapChain.NativePointer;
}
// Draw Overlay(s)
else if (_overlayEngine != null)
{
foreach (var overlay in _overlayEngine.Overlays)
overlay.Frame();
_overlayEngine.Draw();
}
}
#endregion然后,当它试图绘制()时,我使用了一个断点,它将转到DXOverlayEngine.cs类的这一行:
_spriteEngine.DrawString(textElement.Location.X, textElement.Location.Y, textElement.Text, textElement.Color.R, textElement.Color.G, textElement.Color.B, textElement.Color.A, font);然后转到这个部分的DXSprite.cs:
public void DrawString(int X, int Y, string text, int R, int G, int B, int A, DXFont F)
{
Color4 blendFactor = new Color4(1.0f);
Color4 backupBlendFactor;
int backupMask;
var backupBlendState = _deviceContext.OutputMerger.GetBlendState(out backupBlendFactor, out backupMask);
_deviceContext.OutputMerger.SetBlendState(_transparentBS, blendFactor);
BeginBatch(F.GetFontSheetSRV());
int length = text.Length;
int posX = X;
int posY = Y;
Color4 color;
Vector4 Vec = new Vector4(R > 0 ? (float)(R / 255.0f) : 0.0f, G > 0 ? (float)(G / 255.0f) : 0.0f, B > 0 ? (float)(B / 255.0f) : 0.0f, A > 0 ? (float)(A / 255.0f) : 0.0f);
color = new Color4(Vec);
for (int i = 0; i < length; ++i)
{
char character = text[i];
if (character == ' ')
posX += F.GetSpaceWidth();
else if (character == '\n')
{
posX = X;
posY += F.GetCharHeight();
}
else
{
Rectangle charRect = F.GetCharRect(character);最后,它在DXFont.cs类中执行F.GetCharRect(字符)行:
public Rectangle GetCharRect(char c)
{
Debug.Assert(_initialized);
return _charRects[c - StartChar];
}我在方法GetCharRect上使用了断点,例如,在本例中,变量c的值是: 163'£,变量StartChar中的值是33 '!‘
然后,它会在线路上显示异常:
return _charRects[c - StartChar];我试着问车主这个问题,到目前为止,他告诉我的是:
“听起来像是在试图画一个它还没有准备好的角色……”
我试着尽可能地缩小代码的范围,但它们都是相互联系的。
发布于 2015-05-08 23:29:10
查看DXFont.cs,它似乎只准备了ASCII码在33和127之间的字符
const char StartChar = (char)33;
const char EndChar = (char)127;
const uint NumChars = EndChar - StartChar; 在BuildFontSheetBitmap期间基于此范围设置_charRects。您需要扩展范围以包括要呈现的所有字符
https://stackoverflow.com/questions/30127062
复制相似问题