At the end of the game, throw exception

At the end of the game, throw exception
‘SharpDX.SharpDXException’ (in SharpDX.Direct3D11.dll)
6 same errors.
Since there is no error code, we do not know what is causing the problem.
It’s at the end of the game, so it’s not a problem, but it bothers me.
help me!


*In Japanese.
私は日本人で、英語は機械翻訳です。
一応日本語でも記載しておきます。
ゲーム終了時に下記例外がスローします。同じ物が6つ表示されますが、エラーコードはありません。
終了時なのでなにか問題があるわけでは無いですが、ちょっと気になるので、解決出来るなら対応したいです。

例外がスローされました: ‘SharpDX.SharpDXException’ (SharpDX.Direct3D11.dll の中)

What system are you running on?
どのシステムで実行していますか?

Can you run a blank template game?
空のテンプレートゲームを実行できますか?

You should be implementing Throw/Catch type code to create your own error notifications.
独自のエラー通知を作成するために、スロー/キャッチタイプのコードを実装する必要があります。

1 Like

Thank you for writing in Japanese!

①Windows 10

②yes, But no errors.
実行してみたら、エラーは出ませんでした…

③Understood! I’ll try to find out when the error occurs and implement a throw/catch type code.
解りました!エラーが出るタイミングを調べて、スロー/キャッチタイプのコードを実装してみます。

Thanks for the reply.
本当に有難うね!

1 Like

You have something like this in your main method (program.cs)?
メイン メソッド (program.cs) に次のようなものがありますか?

static void Main()
{
  AppDomain.CurrentDomain.UnhandledException += Handle_UnhandledException;
}

private static void Handle_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
	Debug.WriteLine("Unhandled exception:");
	Debug.WriteLine(e.ToString());
}
1 Like

Thank you for writing in Japanese!

Thanks for the reply!
It wasn’t there, so I added it, but I didn’t catch the error.

That’s really strange, I’m not sure why it’s not caught. I’m sorry, I don’t have any other ideas :frowning:

それは本当に奇妙です、なぜそれが捕まらないのか私にはわかりません。 申し訳ありませんが、他のアイデアはありません:(

1 Like

Thank you for your reply.
I will investigate the timing of the error.

How do you know that there is an exception in the first place? Does the debugger catch it? Or do you see it in the output window?

Thanks for the question.
Error appear in the output window.

You can try adding the exception “SharpDX.SharpDXException” to your “Break when thrown” settings to see if the debugger catches it when exiting the game, hopefully you can see more info then.

image

1 Like

Thanks, I caught the exception!
It was caused by something being drawn on exit, not on exit.
GraphicsDevice.DrawIndexedPrimitives()
Once the error occurs, the next loop does not.
I tried it on two different PC environments, one of which did not have the error.
Both graphics drivers are up to date.
The one with the error is an nVidia RTX 3060Ti .
The one without error is nVidia GTX 1650.
Even in the environment where the error occurs, there seems to be no drawing problem. (Maybe only one frame is wrong, though…)
It will take some time to investigate.

—in Japanese
有難う、例外がキャッチ出来ました!
終了時では無く、終了時に描画している物が原因でした。
GraphicsDevice.DrawIndexedPrimitives()
内でエラーになっているようで、1度エラーになると、その次のループではなりません。
2つのPC環境で試しましたが、一方ではエラーは出ませんでした。
グラフィックドライバーは共に最新で、
エラーになる方は、nVidia RTX 3060Ti 。
エラーにならない方は、nVidia GTX 1650。
エラーになる環境でも、描画は問題は無いようです。(1フレームだけおかしいのかも知れないけど)
調査には時間がかかりそうです。

1 Like

I finally have a solution!
For the sake of future generations, I will describe the details.

・Symptoms
MonoGame: After updating from Ver 3.8.0.1641 to 3.8.1.303, a mysterious exception appears.

The exception is output to VisualStudio’s OutPut Window, but the game does not stop and drawing is fine.
Exception thrown: ‘SharpDX.SharpDXException’ (in SharpDX.Direct3D11.dll)

Different GPUs behave differently
nVidia RTX 3060Ti : exception throw
nVidia GTX 1650 : no problem

・Solution
As taught by persn
In VS2022 Debug → Window → Exception Settings
SharpDX.SharpDXException in the Commond Language Runtine Exception setting.

Call Stack
SharpDX.Direct3D11.dll!SharpDX.Direct3D11.Device.CreateInputLayout(SharpDX.Direct3D11.InputElement[] inputElementDescsRef, int numElements, System.IntPtr shaderBytecodeWithInputSignatureRef, SharpDX.PointerSize bytecodeLength, SharpDX.Direct3D11.InputLayout inputLayoutOut)
SharpDX.Direct3D11.dll!SharpDX.Direct3D11.InputLayout.InputLayout(SharpDX.Direct3D11.Device device, byte[] shaderBytecode, SharpDX.Direct3D11.InputElement[] elements)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(Microsoft.Xna.Framework.Graphics.VertexBufferBindings vertexBuffers)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(bool applyShaders)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, PrimitiveNum);

Debugger Information

Exception thrown: 'SharpDX.SharpDXException' (in SharpDX.Direct3D11.dll)
HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: wrong parameter.

Following up, there seems to be no problem with the various settings before drawing.
Investigating the shaders, we find
I noticed a mistake in the Position semantics of VertexShader’s Input!

struct VS_INPUT_PNC
{
//	float4	m_f4Pos			:	SV_POSITION;	//exception throw
								↓
	float4	m_f4Pos			:	POSITION0;		//ok
};

It was a small mistake, sorry.
Thanks for all your help!


in Japanese

やっと解決が出来ました!
後進の為に、詳細を記載しておきます。

・症状
MonoGame:Ver 3.8.0.1641 → 3.8.1.303 にアップデートすると、謎の例外が出るように。

例外はVisualStudioのOutPut Window に出力されるが、ゲームは止まらないし描画も問題ない。
例外がスローされました: ‘SharpDX.SharpDXException’ (SharpDX.Direct3D11.dll の中)

GPUによって挙動が違う
nVidia RTX 3060Ti :例外
nVidia GTX 1650 :問題なし

・解決方法
persn さん に教えてもらった、
VS2022のデバッグ → ウィンドウ → 例外設定にて、
Commond Language Runtine Exception の、SharpDX.SharpDXException にチェックを入れて調査

コールスタック

SharpDX.Direct3D11.dll!SharpDX.Direct3D11.Device.CreateInputLayout(SharpDX.Direct3D11.InputElement[] inputElementDescsRef, int numElements, System.IntPtr shaderBytecodeWithInputSignatureRef, SharpDX.PointerSize bytecodeLength, SharpDX.Direct3D11.InputLayout inputLayoutOut)
SharpDX.Direct3D11.dll!SharpDX.Direct3D11.InputLayout.InputLayout(SharpDX.Direct3D11.Device device, byte[] shaderBytecode, SharpDX.Direct3D11.InputElement[] elements)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(Microsoft.Xna.Framework.Graphics.VertexBufferBindings vertexBuffers)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(bool applyShaders)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, PrimitiveNum);

デバッガー情報

例外がスローされました: 'SharpDX.SharpDXException' (SharpDX.Direct3D11.dll の中)
HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: パラメーターが間違っています。

追って行くと、描画前までの各種設定には問題が無さそう。
シェーダーを調査すると、
VertexShaderのInputのPositionセマンティクスの間違いに気がついた!

struct VS_INPUT_PNC
{
//	float4	m_f4Pos			:	SV_POSITION;	//例外
								↓
	float4	m_f4Pos			:	POSITION0;		//ok
};

ちょっとしたミスでした、ゴメンネ!
助けてくださった皆様、有難う!

3 Likes

Good job! I’m glad to hear you found the problem, that was a tough one :slight_smile:

よくできた! あなたが問題を見つけたと聞いてうれしいです、それは難しいものでした:)

1 Like