Running a Unity build (.exe) from a batch file
I am creating a build pipeline with TeamCity and have ran into an issue with running the created build from a batch file.
This process used to work fully around 5.3.4p5 but since then when I run this line from the batch file:
set TEST_OUTPUT_FILE=%~dp1testlog.txt
:: run the exe
%1 -logFile %TEST_OUTPUT_FILE%
It initially loads the app in the background but does nothing after that, e.g. Task Manager reports the app is not using any CPU or memory.
When checking the log file the bottom most entry is this error:
IndexOutOfRangeException: Array index is out of range.
at UnityEngine.Display.RecreateDisplayList (System.IntPtr[] nativeDisplay) [0x00030] in C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineDisplayBindings.gen.cs:126
(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDisplayBindings.gen.cs Line: 126)
desktop: 1024x768 60Hz; virtual: 1024x768 at 0,0
Switching to resolution 1024x576 failed, trying lower one
All resolution switches have failed
Screen: DX11 could not switch resolution (1024x576 fs=0 hz=0)
I can confirm:
The file path (%1) is correct
Running Unity 5.4.1p3
App loads correctly if you double click the .exe
App loads correctly if you run it from the Command Prompt
App loads correctly if you add the "-batchmode" command to the exe execution line
This process used to work fully beforehand
This batch file is being triggered by TeamCity
I can only assume it is something to do with DirectX 11 not initialising properly but apart from that, I have no idea.
I appreciate any help you can give.
Update: After looking through the build logs I found this error:
Aborting batchmode due to failure:
Failed to build player.
Unhandled Exception: System.IO.DirectoryNotFoundException: Directory 'C:\TeamCity\buildAgent\temp\buildTmp\745a85f3' not found.
This happens at the previous step before it runs the build, starting to think its a TeamCity thing, will keep investigating.
Answer by Chimera91 · Oct 14, 2016 at 09:20 AM
Found out that using the pre-installed build agent running as a service was the issue.
To fix this install another agent through TeamCity and disable the original agent.
The new agent should not be a service and will run any .exe properly.
This still solved my problem using the latest TeamCity and Unity 2017.2.1. Thanks!
Your answer
