Search Unity

Compiler warnings turning into internal compiler errors

Discussion in 'Scripting' started by Marble, Jun 12, 2012.

  1. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    So I've always lived with a bunch of warnings in the console until today I started getting "internal compiler errors" for the same things! In particular, I've got things like variables that are declared but not used actually keeping Unity from compiling my scripts.

    This happened to anyone else?
     
  2. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    Sometimes after I really did something wrong I get weird errors that only go away after I restart Unity. Could be that you forgot "var" before declaring the variable? I do that all the time.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You know what would help? actually posting the error details instead of leaving us to guess. Magical but true.
     
  4. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    Maybe you switched from PC/Mac/Webplayer build to iOS/Android where #pragma strict is turned on by default for UnityScript?
     
  5. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Thanks for all the suggestions, those of you who had to guess what the problem was.

    The error was
    Code (csharp):
    1. Internal compiler error. See the console log for more information. output was:
    followed by a stream of almost identical warnings:

    Code (csharp):
    1. Assets/Environments/Lighthouse/3D Items/DoorSwing.cs(8,14): warning CS0414: The private field `DoorSwing.swinging' is assigned but its value is never used
    Code (csharp):
    1. Assets/Environments/Character Walks/MainCharController.cs(16,14): warning CS0414: The private field `MainCharController.facing' is assigned but its value is never used
    But the issue is that there were so many of these warnings, and the pane where they are reported does not scroll, so I didn't see at the very bottom where there was an
    Code (csharp):
    1. Unhandled Exception: Mono.CSharp.InternalErrorException: Assets/Duels/Sprites/PlayerBehavior.cs(4,14): PlayerBehavior ---> System.InvalidOperationException: Method 'PlayerBehavior.Start' does not have a method body.
    caused by an incompleted override.

    So the lesson is to make the console window as large as possible, or you might not see the relevant error! (At the same time, it'd be nice to be able to scroll through the bottom half of the console like the top...)
     
  6. pesseba

    pesseba

    Joined:
    Aug 14, 2008
    Posts:
    13
    You can use this lines to prevent this warning error...

    Code (csharp):
    1. #pragma warning disable 169, 414
    2.  
    3.     int unused;
    4.     int assigned = 3;
    5.  
    6. #pragma warning restore 169, 414
    see about: http://www.blackwasp.co.uk/SuppressWarnings.aspx
     
    Last edited: Sep 26, 2012
  7. Morning

    Morning

    Joined:
    Feb 4, 2012
    Posts:
    1,141
    You should not disable warnings. They're there for a reason and you should instead fix them.
    While you can't scroll on the bottom half of the console, you can select all text and copy it.
     
  8. pesseba

    pesseba

    Joined:
    Aug 14, 2008
    Posts:
    13
    I agree with you, prevent warnings is not a solution, and it doesn't solved my problem too...
    But it can be a way to find the origin of the problem... Because the related error line looks fine.
    See my error, and my code:

    Error:
    Internal compiler error. See the console log for more information. output was:Assets/SWFGUI/SWFButton.cs(19,27): warning CS0414: The private field `SWFButton.bt' is assigned but its value is never used

    Code (I'm using the plugin uniSWF):

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using pumpkin.display;
    4. using pumpkin.events;
    5. using pumpkin.ui;
    6. using pumpkin.tweener;
    7. using pumpkin.utils;
    8. using pumpkin.text;
    9.  
    10. //using pumpkin.text.TextField;
    11. public class SWFButton:SWFObject{
    12.    
    13.     //public var mcb:InteractiveMovieClipBehaviour;
    14.     //public var instanceName:String;
    15.     public string label;
    16.    
    17.     //private var mc:MovieClip;
    18.    
    19.     private MovieClip bt;
    20.     private TextField tx;
    21.     private MovieClip cliplabel;
    22.     private string state="out";
    23. ...
    24.  
    The warning says my variable 'bt' is never used, but I use this in my constructor....
    I had converted this class from a UnityScript version, and it works fine in there...
    What's the problem??
     
  9. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    Please show your constructor. If the variable is set but not used it will give you a warning, but a compiler error is weird. Check the whole message in the log. You might find something else causing the error like marble did.
     
    Last edited: Sep 27, 2012
  10. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    If the variable is private, and not accessed in the script (doesn't matter if you set it. Setting without using is pointless) it is considered unused. You get this warning because you might as well delete the variable.
     
  11. pesseba

    pesseba

    Joined:
    Aug 14, 2008
    Posts:
    13
    I found my problem... it was a basic mistake.
    My base class SWFObject had no public or protected declaration for Start()... And I use an override for this method.

    I found this when I commented all the inner content of all classes that this error shows up. I discovered that this warning error just had affected the classes extended from SWFObject, but SWFObject doesn't have error. so... I found!

    The error message don't have direct relationship with the real error... (this kind of message make me lose my hairs...):cool:
     
    Last edited: Sep 27, 2012
  12. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,632
    That's exactly the error and solution Marble had a few posts above.
     
  13. Japu

    Japu

    Joined:
    Jul 21, 2013
    Posts:
    2
    This has happened to me when I have a data type with same name within a class as an enum, and there are some cross references these types. For me it has been a problem but the error coding is not easy to find. Check out the latest changes and go slowly checking.

    Luck.
     
  14. Archie888

    Archie888

    Joined:
    May 17, 2014
    Posts:
    41
    I had an issue like this, with threaded stuff, tasks involved etc, using Parse with unity. In my case, I had one error line, in which it seemed that warning messages were written on. If you have a scenario like mine, scroll down the whole message, and you will see that this is not only about warnings turning into errors, but there is an actual error message there in the end, with a long stack trace.

    My specific error message was: "Unhandled Exception: System.ArgumentException: Trying to emit a local from a different ILGenerator."

    I had a try-catch block in the specific code that was causing issues. Removing that try-catch block removed my specific issue.

    Very weird. I'll repeat this post in all threads on the issue I can find, perhaps it can help someone.
     
    Tom-Li likes this.
  15. JakubNei

    JakubNei

    Joined:
    Jul 20, 2013
    Posts:
    26
    Still happens to me, seems like if you mix Unity code compile and writing new code at the same time this error happens. You can restart Unity and it's fixed, it's still annoying though.
     
  16. PerlKr

    PerlKr

    Joined:
    Aug 28, 2015
    Posts:
    1
    You really saved mine. Error was hiding inside warning thing. Thanks a lot Archie!
     
    Tom-Li likes this.