Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

My C# class is causing the Unity Editor to crash. is there a way to find out why?

Discussion in 'Scripting' started by rickblacker, May 27, 2015.

  1. rickblacker

    rickblacker

    Joined:
    May 1, 2014
    Posts:
    266
    Hi all.
    I have a C# script that is doing some work. It uses one of our C# Dlls. I'm not sure why, but when I stop play mode, my C# script is causing the editor to crash. I'd like to try and find out why this is happening.

    Was hoping someone might be able to assist me. Is there a log i can be looking? Some kind of log settings that will verbosely write data out to a log somehow? Or is there a way to trap this error send the message to the Output window?

    Any help will be greatly appreciated.
    Thanks
    Rick
     
  2. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    974
    Try attaching your debugger before exiting play mode.

    In MonoDevelop, under the Run menu there is an Exceptions... tool which will allow you to select Exceptions to stop on. Try adding all Exceptions to the list and then exiting play mode.
    upload_2015-5-27_14-45-53.png

    This might help you find unexpected exceptions that are being thrown by your external dll. If any of your code is running in a separate thread, an unhandled exception can bubble to the top of the stack and cause Unity to crash.
     
  3. rickblacker

    rickblacker

    Joined:
    May 1, 2014
    Posts:
    266
    Thanks, I will try Mono. I've been using the Visual Studio plugin, but will give this a try. Right now, there is no multi thread activity going on.
     
  4. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    974
    You can do the same with Visual Studio.

    Under the Debug menu is an Exceptions... tool. You will want to make sure the User-unhandled box is ticked for the Common Language Runtime Exceptions but if that isn't showing anything, you could also try ticking the Thrown checkbox. This will cause the debugger to halt your program execution anytime an exception is thrown, which might help your investigation.

    upload_2015-5-27_15-56-55.png

    Again, attach the debugger before exiting play mode and initiating the crash.
     
    blizzy likes this.
  5. rickblacker

    rickblacker

    Joined:
    May 1, 2014
    Posts:
    266
    For some reason, I'm not able to get the Monodevelop debugger to work correctly with Unity. Won't stop at breakpoints. Plus, i have constantly press on the attach button go get mono debugger to attach with Unity.

    Then in Visual Studio, I checked what you suggested, but still not getting any clue. When I clicked on the triangle to stop running the app/game is when Unity Editor will fail on me.
     
  6. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    974
    Can you confirm that you are able to hit breakpoints in Visual Studio?

    Also, do you think the crash is being caused by your script, or by the dll? Is the dll yours? Do you have the source?

    Sorry, I don't have much experience troubleshooting Unity specifically so I don't know if there are any logs that might be generated. You could try poking around the Unity folder for an error log, stack trace or memory dump. Maybe someone with more experience with Unity can help on that front.
     
  7. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    969
  8. rickblacker

    rickblacker

    Joined:
    May 1, 2014
    Posts:
    266
    It's definitely being generated due to my script. My script is working with audio devices. If i comment out that section of the C# script, the Unity Editor does not crash. Oddly, in a normal Windows Form application, the same C# class / script runs fine, without fail.


    steego, i will take a look at your link... Thanks!