sarbian

KSP Plugin debugging and profiling for Visual Studio and Monodevelop on all OS

Recommended Posts

Having problems with the Profiler on Unity-on-linux.

As soon as the debug LinuxPlayer (renamed to KSP.x86_64, etc.) runs and the UnityEditor connects to it, the Player stops (as if at breakpoint). If I then switch (Profiler tab) the Connected Player from LinuxPlayer(localhost) to Editor, the Player resumes and runs as if nothing happens. Choosing it again freezes it again.

Have someone any experience with the Profiler on linux and, perchance, knows a fix/workaround?

Share this post


Link to post
Share on other sites
11 minutes ago, allista said:

Having problems with the Profiler on Unity-on-linux.

As soon as the debug LinuxPlayer (renamed to KSP.x86_64, etc.) runs and the UnityEditor connects to it, the Player stops (as if at breakpoint). If I then switch (Profiler tab) the Connected Player from LinuxPlayer(localhost) to Editor, the Player resumes and runs as if nothing happens. Choosing it again freezes it again.

Have someone any experience with the Profiler on linux and, perchance, knows a fix/workaround?

KSP Main Menu > Settings > General > Simulate In Background ?

Share this post


Link to post
Share on other sites
7 minutes ago, sarbian said:

KSP Main Menu > Settings > General > Simulate In Background ?

Nope, checked it first of all. It does look like SIGSTOP or breakpoint. Editor connects, process stops (black screen, no CPU activity); Editor disconnects, everything resumes.

The only notion of a similar problem I found was about an Android player that similarly freezes/unfreezes on connection, but that was an old thread with the "update version of Unity" kind of solution.

Edit: debugging with MonoDevelop works alright, though.

Edited by allista

Share this post


Link to post
Share on other sites
1 minute ago, allista said:

Nope, checked it first of all. It does look like SIGSTOP or breakpoint. Editor connects, process stops (black screen, no CPU activity); Editor disconnects, everything resumes.

The only notion of a similar problem I found was about an Android player that similarly freezes/unfreezes on connection, but that was an old thread with the "update version of Unity" kind of solution.

I ll get on with the obvious checks : the Unity version match KSP's (5.4) ? 

Share this post


Link to post
Share on other sites
Just now, sarbian said:

I ll get on with the obvious checks : the Unity version match KSP's (5.4) ? 

It does not, because linux version of Unity is still a beta with versions like 2017.1.0b. But there's no errors in Editor.log, either.

I'll try to setup the 5.4.0p4 in POL and see how that works...

Share this post


Link to post
Share on other sites

I see a bunch of 5.4 downloads in the thread.

  • Like 1

Share this post


Link to post
Share on other sites
21 minutes ago, sarbian said:

I see a bunch of 5.4 downloads in the thread.

Stupid me, really :confused:

Thank's a lot, that did help.

Share this post


Link to post
Share on other sites

This worked like a charm for me. Mega props for figuring this out! 

Share this post


Link to post
Share on other sites

Debugging update on Windows for :

KSP 1.4.3 build 2152

Unity3D 2017.1.3p1

Visual Studio 2017 v15

Original Instructions are mostly OK except for :

- debug version of Unity player needs to be named "Unity.exe" (see notes below)

- mklink command now needs to be "mklink /J Unity_Data KSP_x64_Data" (case insensitive, see notes below)

[NOTES]

If debug player is not named "Unity.exe", unity addon will not recognize it and will present empty "Select Unity Instance" window, offering network debugging via "Input IP" option where it needs both IP address and PORT.

For IP address its simple, if VS debugger and game are on same machine but, there will be problem with PORT since (at least in my case) debug player changes port with each game run.

Debug player is looking for Data folder named as "NameOfEXE_Data".

[/NOTES]

Note also that because KSP 1.4.x now runs on new version of Unity3D, old debugger addons no longer work (at least in my case, your expirience may differ) for example Xamarin or older VS2015.

... and yes yes i know i necropost, but to me this is "official" thread about debugging, and this is where i first got a working debug. I felt it needed updating.

Paging dr.  @sarbian please as time permits to update OP. Thanks in advance !

Share this post


Link to post
Share on other sites
Posted (edited)

I have it named as: KSP_x64_Dbg.exe and it works fine for me. But in mi case the linked folder is KSP_x64_Dbg_Data so that might be it...

Edited by Dagger

Share this post


Link to post
Share on other sites
Posted (edited)

Well... I have no problem with the exe and link naming in my debugging install. 

Your problem looks like what happends when the debug file (PlayerConnectionConfigFile) is missing.

Edited by sarbian

Share this post


Link to post
Share on other sites
6 hours ago, sarbian said:

Well... I have no problem with the exe and link naming in my debugging install. 

Your problem looks like what happends when the debug file (PlayerConnectionConfigFile) is missing.

I then stand corrected. Thanks for reply ! I was lucky (and spent lots of time on it) to find out why is my install so finicky :)

Share this post


Link to post
Share on other sites

@sarbian Thanks for providing these directions! :) After about four years of debugging plugins the old fashioned way with just Debug.Log, I finally got tired of it, upgraded my Visual Studio, and tried to set up VS debugging. The updated directions work great for my laptop, and I'm able to debug KSP 1.4.3 with Unity 2017.1.3.p1. Following the same directions on my desktop, however, my Visual Studio 2017 isn't able to connect to the KSP development build. I'm not sure why, as both KSPs on the laptop and desktop are set up the same, both Visual Studios and Unity editors are set up the same as well. When I select Debug -> Attach Unity Debugger, I see the following:

25FApmD.png

I tracked down the output_log, and here's what I see in the first few lines:

Spoiler

Mono path[0] = 'C:/KSPDev/KSP_x64_Dbg_Data/Managed'
Mono config path = 'C:/KSPDev/KSP_x64_Dbg_Data/Mono/etc'
PlayerConnection initialized from C:/KSPDev/KSP_x64_Dbg_Data (debug = 0)
PlayerConnection initialized network socket : 0.0.0.0 55175
Multi-casting "[IP] 10.0.1.11 [Port] 55175 [Flags] 3 [Guid] 308044216 [EditorId] 3247424759 [Version] 1048832 [Id] WindowsPlayer(Enterprise) [Debug] 1" to [225.0.0.222:54997]...
Waiting for connection from host on [0.0.0.0:55175]...
Timed out. Continuing without host connection.
Started listening to [0.0.0.0:55175]
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,defer=y,address=0.0.0.0:56216
PlayerConnection already initialized - listening to [0.0.0.0:55175]
Player data archive not found at `C:/KSPDev/KSP_x64_Dbg_Data/data.unity3d`, using local filesystem
Initialize engine version: 2017.1.3p1 (02d73f71d3bd)
GfxDevice: creating device client; threaded=1
Direct3D:
    Version:  Direct3D 9.0c [nvldumdx.dll 23.21.13.8813]
    Renderer: NVIDIA GeForce GTX 680
    Vendor:   NVIDIA
    VRAM:     4063 MB (via DXGI)
    Caps:     Shader=30 DepthRT=1 NativeDepth=1 NativeShadow=1 DF16=0 INTZ=1 NULL=1 RESZ=0 SlowINTZ=0 ATOC=1 BC4=1 BC5=1
Begin MonoManager ReloadAssembly

For my laptop, where I can debug successfully, here's the output:

Spoiler

Mono path[0] = 'C:/KSPDev/KSP_x64_Dbg_Data/Managed'
Mono config path = 'C:/KSPDev/KSP_x64_Dbg_Data/Mono/etc'
PlayerConnection initialized from C:/KSPDev/KSP_x64_Dbg_Data (debug = 0)
PlayerConnection initialized network socket : 0.0.0.0 55211
Multi-casting "[IP] 10.0.0.238 [Port] 55211 [Flags] 3 [Guid] 4135053456 [EditorId] 3247424759 [Version] 1048832 [Id] WindowsPlayer(Columbia) [Debug] 1" to [225.0.0.222:54997]...
Waiting for connection from host on [0.0.0.0:55211]...
Timed out. Continuing without host connection.
Started listening to [0.0.0.0:55211]
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,defer=y,address=0.0.0.0:56456
PlayerConnection already initialized - listening to [0.0.0.0:55211]
Player data archive not found at `C:/KSPDev/KSP_x64_Dbg_Data/data.unity3d`, using local filesystem
Initialize engine version: 2017.1.3p1 (02d73f71d3bd)
GfxDevice: creating device client; threaded=1
Direct3D:
    Version:  Direct3D 9.0c [nvldumdx.dll 22.21.13.8205]
    Renderer: NVIDIA GeForce GTX 960M
    Vendor:   NVIDIA
    VRAM:     2019 MB (via DXGI)
    Caps:     Shader=30 DepthRT=1 NativeDepth=1 NativeShadow=1 DF16=0 INTZ=1 NULL=1 RESZ=0 SlowINTZ=0 ATOC=1 BC4=1 BC5=1
Begin MonoManager ReloadAssembly

Here's what my development folders look like:

hFKeRr9.png

ukQkwR7.png

Finally, here's a random image:

wsLolhj.png

;)

Any ideas what's going on with my desktop install of the development environment? It's really puzzling that the laptop works but the desktop does not. Off the top of my head, I wonder if there's a firewall blocking the debugger on the desktop. Has anybody else seen this issue?

Thanks for your help! :)

Share this post


Link to post
Share on other sites

For some it seems the PlayerConnectionConfigFile I provide does not work. Launch Unity with an empty project, find the build game menu (File I think ?) set the build to dev, launch the build and save somewhere. You should have a PlayerConnectionConfigFile somewhere in there that hopefully will be better tailored to your PC.

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, sarbian said:

For some it seems the PlayerConnectionConfigFile I provide does not work. Launch Unity with an empty project, find the build game menu (File I think ?) set the build to dev, launch the build and save somewhere. You should have a PlayerConnectionConfigFile somewhere in there that hopefully will be better tailored to your PC.

Hm, maybe something else is failing? I followed the directions but I have the same issue: the debugger won't notice the KSP app. I also tried attaching to my empty Unity project and it doesn't show up either.

I can attach to the Unity editor itself:

dQpLIIv.png

Share this post


Link to post
Share on other sites
Posted (edited)

I've tried also with alternate PlayerConnectionConfigFile generated on my system (which is kind of paradox since locally generated file is actually original, but i'm splitting hairs here :) ) and no luck.

I then renamed my KSP debug player to "Unity.exe" (and added .pdb file from same editor install location where i copied debug player), made new link to folder and it (again) worked without a hitch.

When i was googling around i found some post over on unity forums that unity debugger for VS needed to find "Unity.exe" process. Ehhh i guess this works too.

If both debug player and editor are run at the same time, you can tell the difference because editor will have project name in list of debug listeners, ksp debug player will have that entry empty.

Finally, if above does not work you can resort to listing all processes in system that have open listen ports (two TCP and one UDP, usually the second TCP is one you should connect to). Then open VS unity debugger and choose "Input IP" and enter 127.0.0.1:PORT. Problem is (at least on my machine) that every time ksp debug player is run, PORT number changes :(

Oh and word of caution : i just noticed that VS unity debugger sees KSP debug player as "Editor". I don't know if it matters, but i tried inserting a breakpoint and it seems to work.

Edited by fatcargo
typo
  • Like 1

Share this post


Link to post
Share on other sites

Just an FYI, Someone contacted me claiming that one of my mods was generating endless exceptions in his debugger build and was saying it was mu fault.  When he finally sent me the info on the exception, it turned out that there was a try/catch, where I was writing the exception message to the log, and it was THAT which was null (the exception was for a filenotfound).  So somehow, his debug buld was creating its own issues.

That being said, I think I’ll be trying this for 1.4.4 in a few days.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now