Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to debug webGL

Discussion in 'WebGL' started by arumiat, Apr 14, 2015.

  1. arumiat

    arumiat

    Joined:
    Apr 26, 2014
    Posts:
    321
    Hi there

    I know some basic C# for game scripting purposes but anything else is beyond me, especially browser scripting.
    I am wondering how I can go about actually debugging and viewing exceptions so that I can send them to my developer / post them here?

    - Currently I have been building a project, and get told that exceptions have occurred, and I need to enable these in the build to be able to see what they are.
    - I've rebuilt the exact same project with the only change being that exceptions are enabled, but the game isn't working properly (my camera movement isn't working)
    - how can I get access to the exceptions to try and see what these are?
    - I should note that if I build and run to a local server, the same issue is occurring

    Any advice hugely appreciated,
    T
     
  2. hyperhippo

    hyperhippo

    Joined:
    Jan 16, 2014
    Posts:
    37
    the problem with that is, when you add exception handling, the build actually changes the code that's generated, adding things like try catches for null reference exceptions, you can potentially cause different problems just by turning it on, not to mention if it brings your game over the memory heap limit you set, or the memory limit of you browser process it will crash.

    best bet, start ripping things out of your project one by one until it doesn't break any more, and cross your fingers for a better implementation in the future.
     
    arumiat likes this.
  3. arumiat

    arumiat

    Joined:
    Apr 26, 2014
    Posts:
    321
    Yes thanks hyperhippo, - it seems like things got worse after enabling exceptions a while back oddly enough.

    It would still be good to know how to actually access these errors?

    I'm hoping for a lot more stability in 5.1!
     
  4. hyperhippo

    hyperhippo

    Joined:
    Jan 16, 2014
    Posts:
    37
    I've had to resort mostly to adding lots and lots of Debug.Log statements, make sure you check your references for null before you run most of your code. You will need to be defensive and clean up after yourself in your classes and rely less on Unity and Monobehaviours to just manage your references for you and fail silently.
     
  5. arumiat

    arumiat

    Joined:
    Apr 26, 2014
    Posts:
    321
    Ah so I misunderstood the point of enabling exceptions. I thought this meant that a console window would popup somewhere in the webGL frame or the browser that would list the exceptions that are occurring.

    Is the point of 'enabling exceptions' in fact just that there is recognition that exceptions are occurring, but that the game will play anyway? ie. it wont stop and crash as previously?

    Secondly would it help to build development builds, - I remember this use to give a console window in webplayer that would list errors
     
  6. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    its a bit of both, enabling exceptions, actually alters your code so that the exceptions won't show up on a popup over top of your browser content. They should be output to the javascript console though.
     
    arumiat likes this.
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you're just talking about Debug.Log, the console is dependent on the browser. In Safari, for example, use "Show error console" in the Develop menu. It doesn't depend on making development builds.

    --Eric
     
    arumiat likes this.
  8. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    The console log should tell you the line number and character position in the code where the exception was thrown. You can inspect the code in a text editor and often find the exception type and info string from there, even in builds where exceptions are disabled. It is a shame the exception info string isn't printed out in the standard error message, it should be possible to do that without the overhead and effect on code generation of enabling exception traps.

    You can also use the REPL to inspect variables, look in "memory", and generally figure out what might have gone wrong, and you can edit the generated JavaScript to add additional diagnostics.

    It would help a lot if it were possible to convert JavaScript function names into the original c# names. I guess this is mostly an IL2CPP thing.
     
    arumiat likes this.
  9. arumiat

    arumiat

    Joined:
    Apr 26, 2014
    Posts:
    321
    In firefox hitting f12 brings up a console window that lets you debug, cool