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. Dismiss Notice

WebGL RuntimeError: invalid conversion to integer

Discussion in 'WebGL' started by PineTreeDev, Oct 14, 2021.

  1. PineTreeDev

    PineTreeDev

    Joined:
    Apr 22, 2019
    Posts:
    31
    Hello,

    WebGL builds in my project, build and run. The game works as expected, but, only in WebGL, after around 20 minutes the browser throws a modal error window with the following error:

    After closing the modal window, the browser console starts throwing a new error saying:
    Overall the error gives me zero information on where and how it is being generated for me to pinpoint and fix it.
    The error does not happen in the editor and other types of builds, which makes me think this is a problem with the cpp side of unity, and a bug.

    Does anyone know what is going on and how to fix it?
    Thank you for your help
     
  2. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    241
    I know that you have to Mathf.Clamp01() values for a Color in WebGL.
    But i don't know if this is the same problem ;)

    Code (CSharp):
    1. float x_vector, y_vector;
    2. //WebGL integer overflow on new Color() without Mathf.Clamp01()
    3. x_vector = Mathf.Clamp01((((sample_l - sample_r) + 1) * 0.5f);
    4. y_vector = Mathf.Clamp01((((sample_d - sample_u) + 1) * 0.5f);
    5. Color col = new Color(x_vector, y_vector, 1f, 1f);
     
  3. PineTreeDev

    PineTreeDev

    Joined:
    Apr 22, 2019
    Posts:
    31
    Thanks for the reply!

    The error is so rare, I've fixed a number of things in the project since I posted this and the error did not appear again.
    But I think your answer is valuable, if it happens again I'll try to search in the codebase if we have some colors that might be causing the problem