OpenTK教程运行报错:程序退出代码-1073740791求助
问题:OpenTK 4.8.2 实例化GameWindow时程序退出,错误代码0xc0000409
环境信息
- .NET 8.0
- OpenTK 4.8.2
- Visual Studio Code
项目配置(.csproj)
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <PackageReference Include="OpenTK" Version="4.8.2" /> </ItemGroup> </Project>
项目代码
Game.cs
using OpenTK.Windowing.Desktop; using OpenTK.Mathematics; namespace ARPG { public class Game : GameWindow { public Game(int width, int height, string title) : base(GameWindowSettings.Default, new NativeWindowSettings() { ClientSize = new Vector2i(width, height), Title = title }) { } } }
Program.cs
namespace ARPG { class Program { static void Main(string[] args) { Game game = new Game(800,600,"Game"); game.Run(); } } }
错误信息
The program '[3112] MAIN.exe' has exited with code -1073740791 (0xc0000409).
解决方法
1. 补充缺失的OpenTK依赖包
OpenTK 4.x版本需要OpenTK.Windowing.GraphicsLibraryFramework包提供原生窗口依赖,在.csproj中添加该包引用,版本与OpenTK保持一致:
<PackageReference Include="OpenTK.Windowing.GraphicsLibraryFramework" Version="4.8.2" />
2. 指定平台目标为x64
OpenTK的原生依赖对Any CPU支持不佳,修改.csproj的PropertyGroup,添加平台目标:
<PropertyGroup> <!-- 保留原有配置 --> <PlatformTarget>x64</PlatformTarget> </PropertyGroup>
3. 安装VC++运行库
错误代码0xc0000409通常和缺少VC运行时有关,安装对应版本的Microsoft Visual C Redistributable即可解决。
内容的提问来源于stack exchange,提问作者bna3p45vnh
相关产品推荐
相关产品推荐

