You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 04:07:10