Search code examples
c#teamcityopentk

Run OpenTk dependent exe on TeamCity throws AccessViolationException


What's happening?

  • TC build step via either Command Line (tried custom script as well as Executable with parameters)or .Net process runner
  • What I am trying to run is an application that uses OpenTk.
  • When I run the application by calling it con cmd it runs without problems.
  • when I run from TC I get the error:

(removed timestamps to make it more readable)

Starting: D:\TeamCity9\buildAgent\temp\agentTmp\custom_script3388580896349143851.cmd [] out - in directory: D:\TeamCity9\buildAgent\work\5b9612e40cf3fd7d\BuildSteam [] err - D:\TeamCity9\buildAgent\temp\agentTmp\custom_script3388580896349143851.cmd [] out - [] out - Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. [] out - at OpenTK.Graphics.OpenGL.GL.CreateProgram() [] out - at Duality.Resources.ShaderProgram.AttachShaders(ContentRef`1 v, ContentRef`1 f, ContentRef`1 g) in d:\TeamCity9\buildAgent\work\df69930dfe788c6f\Duality\Resources\ShaderProgram.cs:line 208 [] out - at Duality.Resources.ShaderProgram..ctor(ContentRef`1 v, ContentRef`1 f) in d:\TeamCity9\buildAgent\work\df69930dfe788c6f\Duality\Resources\ShaderProgram.cs:line 188 [] out - at Duality.Resources.ShaderProgram.InitDefaultContent() in d:\TeamCity9\buildAgent\work\df69930dfe788c6f\Duality\Resources\ShaderProgram.cs:line 60 [2015-03-20 19:30:45,651] out - at Duality.ContentProvider.InitDefaultContent() in d:\TeamCity9\buildAgent\work\df69930dfe788c6f\Duality\ContentProvider.cs:line 52 [] out - at SceneBaker.Program.Main(String[] args)

I am running TC and the agent (in the same machine) as a user with Admin privileges.

What I tried

Running in all possible ways on the command line Created a scriptcs script that checked whether the user is not an admin and if not it elevates this is failing with an Invalid operation exception.. investigating.

Tried turning off the firewall to no effect Tried reinstalling the GC drivers to no effect

EDIT : further investigation shows that that exception was just an error on how I was running the process and I get the same Unhandled Exception: System.AccessViolationException

EDIT II : After adding some logging I can see that TC does somehow make the detected graphics driver the incorrect one:

Info: OpenGL initialized Info: Vendor: Microsoft Corporation Info: Version: 1.1.0 Info: Renderer: GDI Generic <--- here it should be Intel HD Graphics 4000 Info: Shading language version:

Any ideas what could make this program work from TC? I need this to run in a specific order on the build steps

Cheers


Solution

  • Ok the problem was that teamcity agent was running as a service, and services can't create OpenGl contexts, once the agent was running from command line then it works.