Search Unity

The same problem ArgumentException

Discussion in 'Immediate Mode GUI (IMGUI)' started by Ceciaman, Jul 30, 2013.

  1. Ceciaman

    Ceciaman

    Joined:
    Jul 30, 2013
    Posts:
    52
    Hi,
    i've this problem....
    in loop for i've sometime:
    ArgumentException: Getting control 32's position in a group with only 32 controls when doing Repaint
    Aborting
    error in bold

    how i can solve it?



    void OnGUI() {...................................

    GUI.Box(new Rect(10-valore_utenti, 10, 210, sH-170), "Giocatori liberi: "+liberi);

    List<string> users = new List<string>();

    foreach ( User user in currentActiveRoom.GetUserList().Values ) {

    users.Add(user.GetName());
    }

    users.Sort();
    userStrings = users.ToArray();

    GUILayout.BeginArea(new Rect(20-valore_utenti, 80, 200, sH-190));

    userScrollPosition = GUILayout.BeginScrollView (userScrollPosition,false, true, GUILayout.Width(190), GUILayout.Height(sH-250)) ;
    liberi=userStrings.Length;


    for(int i = 0;i <liberi;i++){


    if(GUILayout.Button (userStrings)) {
    schedaUtente=userStrings;
    showPopUp = true;

    }

    }



    GUILayout.EndScrollView();

    GUILayout.EndArea();
     
  2. dodo

    dodo

    Joined:
    Jul 13, 2011
    Posts:
    49
    Unity calls OnGUI multiple times in the same frame with different active events, and expects that you render the same amount of GUI objects in each call.

    What's happening in your case is most probably something like this:

    - Unity calls your OnGUI method with the Layout event active, your userlist has 31 members and you draw 31 buttons. Unity calculates the positions of the gui controls to be able to draw them during the Repaint event.

    - Then unity calls your OnGUI method again, this time with the Repaint event active, but this time your userlist has changed and it has 32 members. Unity gives the error because it doesn't now the position of the new button you drew, since it wasn't calculated in the layout event.

    I'm guessing your user list is being updated in another thread, otherwise it wouldn't be possible for the list to change between two OnGUI calls in the same frame.

    TLDR : Make sure you're drawing the same amount of GUI controls for each OnGUI call in the same frame :)
     
  3. Ceciaman

    Ceciaman

    Joined:
    Jul 30, 2013
    Posts:
    52
    Hi dodo thank's for the answer,
    I'm in you second step
    My userlist change in every moment.
    Can you give me a solution to force or to give priority at this operation?