Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jonayoung · Jul 11, 2018 at 02:33 AM · webglbuildingplayer settingsexceptions

Random Unrelated Exceptions thrown in WebGL Build (unity 2018)

I'm getting a lot of strange exceptions from my WebGL build. The exceptions do not turn up in the editor at all. Plus the exceptions being thrown don't seem to be at all related to what my code is doing. In addition, the exceptions seem to change from build to build even when unrelated and small code changes are made (such as adding or removing a Debug.Log()).

For example when I check the javascript console in chrome/Firefox, once I got: "MethodAccessException: Attempt to access method". Removing or adding a Debug.Log and rebuilding sometimes then switches it to: "ArgumentException: Name has invalid chars at System.IO.FileStream..ctor" But other code changes also cause it to switch and there seems to be no rhyme or reason why. I also got "AbandonedMutexException" a few times and a few others that appeared to be to do with threading even though there is no threading in my code.

I narrowed down (using full exception support with stack trace and debug logs) which line was causing the problem and it was simply the construction of a class. I thought it might be because the class implements an interface with a covariant generic type but then I contructed that class in another context and execution didn't stop there.

This all seems very strange and obscure. I have copied the offending class below. I guess I'd like to know if anyone else has had similar issues and if they managed to resolve it or if they know what would cause this.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System;
 
 namespace JY.Collections
 {
     /// <summary>
     /// Only allows the retrieval of items by index
     /// </summary>
     /// <typeparam name="TSuper">the type</typeparam>
     public class DelegateReadOnlyList<T,U> : IReadOnlyList<T>
     {
 
         private class Enumerator : IEnumerator<T>
         {
             private DelegateReadOnlyList<T,U> list;
             private int internalIdx;
 
             public Enumerator(DelegateReadOnlyList<T,U> list)
             {
                 this.list = list;
                 Reset();
             }
 
             public T Current
             {
                 get
                 {
                     return list[internalIdx];
                 }
             }
 
             object IEnumerator.Current
             {
                 get
                 {
                     return list[internalIdx];
                 }
             }
 
             public void Dispose()
             {
                 //nothing to do here
             }
 
             public bool MoveNext()
             {
                 internalIdx++;
                 return internalIdx < list.Count;
             }
 
             public void Reset()
             {
                 internalIdx = -1;
             }
         }
         /// <summary>
         /// The type of delegate that is called by this listener
         /// </summary>
         /// <param name="input">the input parameter</param>
         public delegate T IndexDelegate(int idx);
 
         /// <summary>
         /// The internal list to wrap
         /// </summary>
         private IReadOnlyList<U> internalCollection;
         private IndexDelegate del;
 
         /// <summary>
         /// Constructs the collection
         /// </summary>
         /// <param name="internalList">The internal list</param>
         public DelegateReadOnlyList(IReadOnlyList<U> internalArray, IndexDelegate del)
         {
             this.internalCollection = internalArray;
             this.del = del;
         }
 
         public T this[int index]
         {
             get
             {
                 return del(index);
             }
         }
 
         /// <summary>
         /// The count
         /// </summary>
         public int Count
         {
             get
             {
                 return internalCollection.Count;
             }
         }
 
         public IEnumerator<T> GetEnumerator()
         {
             return new Enumerator(this);
         }
 
         IEnumerator IEnumerable.GetEnumerator()
         {
             return new Enumerator(this);
         }
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by jonayoung · Aug 20, 2018 at 02:41 AM

So in the end the strangest thing mostly fixed the issue. I just randomly changed the class a little and WebGL builds started working again. I removed a generic argument and added a delegate, the adjustment can be seen below. However it does not make sense that this fixed the issue because the code worked and compiled in other platforms just. Perhaps there is some strange bug which means that you cannot have multiple generic arguments if implementing from a class with only one with the WebGL target. Of course none of this explains the completely random exceptions I was getting. But I thought I would post what I did anyway in case anyone else comes across this problem.

Note: I was using WebAssembly, targetting .NET 4x, with explicit exceptions only in the WebGL build settings. The builds did not work in Chrome and didn't work at all if there was no exception support.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System;
 
 namespace JY.Collections
 {
     /// <summary>
     /// Only allows the retrieval of items by index
     /// </summary>
     /// <typeparam name="TSuper">the type</typeparam>
     public class DelegateReadOnlyList<T> : IReadOnlyList<T>
     {
 
         private class Enumerator : IEnumerator<T>
         {
             private DelegateReadOnlyList<T> list;
             private int internalIdx;
 
             public Enumerator(DelegateReadOnlyList<T> list)
             {
                 this.list = list;
                 Reset();
             }
 
             public T Current
             {
                 get
                 {
                     return list[internalIdx];
                 }
             }
 
             object IEnumerator.Current
             {
                 get
                 {
                     return list[internalIdx];
                 }
             }
 
             public void Dispose()
             {
                 //nothing to do here
             }
 
             public bool MoveNext()
             {
                 internalIdx++;
                 return internalIdx < list.Count;
             }
 
             public void Reset()
             {
                 internalIdx = -1;
             }
         }
         /// <summary>
         /// The type of delegate that is called by this listener
         /// </summary>
         /// <param name="input">the input parameter</param>
         public delegate T IndexDelegate(int idx);
         /// <summary>
         /// The type of delegate that is called by this listener
         /// </summary>
         /// <param name="input">the input parameter</param>
         public delegate int CountDelegate();
 
         /// <summary>
         /// The internal list to wrap
         /// </summary>
         private IndexDelegate del;
 
         /// <summary>
         /// The internal list to wrap
         /// </summary>
         private CountDelegate countDel;
 
         /// <summary>
         /// Constructs the collection
         /// </summary>
         /// <param name="internalList">The internal list</param>
         public DelegateReadOnlyList(CountDelegate countDel, IndexDelegate del)
         {
             this.del = del;
             this.countDel = countDel;
         }
 
         public T this[int index]
         {
             get
             {
                 return del(index);
             }
         }
 
         /// <summary>
         /// The count
         /// </summary>
         public int Count
         {
             get
             {
                 return countDel();
             }
         }
 
         public IEnumerator<T> GetEnumerator()
         {
             return new Enumerator(this);
         }
 
         IEnumerator IEnumerable.GetEnumerator()
         {
             return new Enumerator(this);
         }
     }
 }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

88 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I get my audio files to work for WEBGL build? 2 Answers

How can I make PDF files in a Unity WebGL build? 1 Answer

Questions about building game 2 Answers

How do I speed up WebGL builds for testing? 2 Answers

Is it possible to adjust Unity BuildTools files during an Unity Cloud Build 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges