Search Unity

Error: Getting control 0's position in a ...when doing used

Discussion in 'Immediate Mode GUI (IMGUI)' started by Jessy, Feb 11, 2008.

Thread Status:
Not open for further replies.
  1. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I am getting this error:

    "Getting control 0's position in a group with only 0 controls when doing used"

    I am trying to have a GUILayout area with some buttons that appear and disappear, and have everything resized accordingly. Here is the code snippet.

    Code (csharp):
    1. GUILayout.BeginArea (Rect (actionButtonsEdge, buttonGuiTop, buttonSide, buttonSide));
    2.  
    3. for (action = 0; action < lighterActions.length; action++) {
    4.  
    5. if (GUILayout.Button(lighterActions[action], buttonStyle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) {}
    6.  
    7. }
    8.                    
    9. GUILayout.EndArea ();
    I also get

    "GUILayout: Mismatched BeginArea."

    and

    "InvalidOperationException: Operation is not valid due to the current state of the object".

    :?: :? :?:
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There must be more to it than that. :) Because that bit looks OK, I think.

    --Eric
     
  3. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I don't get any errors when I use my original method:

    Code (csharp):
    1. var buttonHeight = buttonSide / lighterActions.length;
    2.  
    3. for (action = 0; action < lighterActions.length; action++) {
    4.  
    5. var buttonTop = buttonGuiTop + (action * buttonHeight);
    6.  
    7. if (GUI.Button(Rect (actionButtonsEdge, buttonTop, buttonSide, buttonHeight), lighterActions[action], buttonStyle)) {}
    8.  
    9. }
    However, that doesn't seem to allow me to use the Margin settings of the GUI Style, which I want to employ in order to get a bit of spacing between the buttons.

    This is the only change being made, and it makes the difference of the script generating errors or not. The buttons actually show up using the first code example, and even still function correctly (with a lot more code not shown here), but I get that error, and I think it adds a bit of weirdness down the road.
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    That looks like a bug + I'd love it if you would file me a repro case using the bugreporter so I can take a look.

    Thanks,
    Nicholas
     
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Ok, I've found the culprit. It's the "if (objects[object] == "1") {}" statement in this code:

    Code (csharp):
    1. private var objects = new Array();
    2. private var object : int;
    3. private var actions = new Array();
    4.  
    5. function Start () {
    6.     objects = ["1", "2", "3"];
    7.     actions = ["one", "two", "three"];
    8. }
    9.  
    10. function OnGUI () {
    11.     var utObjects = objects.ToBuiltin(String);  // so you can modify the objects list and make the GUI grid work
    12.     object = GUI.SelectionGrid (Rect (0, 0, 300, 300), object, utObjects, 1);
    13.    
    14.     if (objects[object] == "1") {
    15.         GUILayout.BeginArea (Rect (300,0,300,300));
    16.         for (action = 0; action < actions.length; action++) {
    17.             if (GUILayout.Button(actions[action], GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) {
    18.             }
    19.         }
    20.         GUILayout.EndArea ();
    21.     }
    22. }
    23.  
    Just click on 2 or 3 and then select 1 again, and you will get the errors. Now, the code works fine if I use the non-GUI Layout method found here:

    Code (csharp):
    1. private var objects = new Array();
    2. private var object : int;
    3. private var actions = new Array();
    4.  
    5. function Start () {
    6.     objects = ["1", "2", "3"];
    7.     actions = ["one", "two", "three"];
    8. }
    9.  
    10. function OnGUI () {
    11.     var utObjects = objects.ToBuiltin(String);  // so you can modify the objects list and make the GUI grid work
    12.     object = GUI.SelectionGrid (Rect (0, 0, 300, 300), object, utObjects, 1);
    13.    
    14.     if (objects[object] == "1") {
    15.         var buttonHeight = 300 / actions.length;
    16.         for (action = 0; action < actions.length; action++) {
    17.             var buttonTop = action * buttonHeight;
    18.             if (GUI.Button(Rect (300, buttonTop, 300, buttonHeight), actions[action]) ) {
    19.             }
    20.         }
    21.     }
    22. }
    But once again, I am trying to incorporate the Margin setting for the buttons, and I am hoping that the Layout method will allow that, because my current, otherwise functional method, does not. Please let me know if a bug report is still in order, or if there is a way to fix this.
     
  6. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    I have also encountered this message, and I believe it is a bug.
    I have uploaded a BugReport with a very small script and project that demonstrates it.
    Case 19168

    P.S. The bug was both in 2.0.0 and 2.0.2, which I just upgraded to.
     
  7. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    ...and 2.0.1, which I was using!
     
  8. Stick

    Stick

    Joined:
    Dec 14, 2007
    Posts:
    37
    Yeah, I have been getting the same error messages too for 2.0.1 and 2.0.2. Here is my code:

    Code (csharp):
    1.  
    2. // Chat Log
    3. else if(logMode == LogMode.Chat)
    4. {
    5.     GUILayout.BeginArea(new Rect(Screen.width-190, 10, 180, 130));
    6.         chatScroll = GUILayout.BeginScrollView(chatScroll);
    7.             GUILayout.Label(chatText.ToString(),"leftalign",GUILayout.Width(179 - GUI.skin.verticalScrollbar.fixedWidth));
    8.         GUILayout.EndScrollView();
    9.     GUILayout.EndArea();
    10. }
    11.  
    12.  
    Any idea Nicholas if this will be looked into? I believe I can avoid it if I use GUI insead of GUILayout, but GUILayout as some auto resizing features for the text in scrollviews that I find indispensable in a lot of cases. I guess it is related to toggling a GUILayout on and off. When its toggled on each time, the three errors are generated.
     
  9. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Please file a bug that shows this in the simplest possible case, then I'll take a look.
     
  10. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I did that exact thing a while ago. I'll dig it up again if necessary.

    ...nevermind, I didn't back up these files when I got my new computer, because I figured UT had it covered. I guess if there was any trouble with the files I sent, you could send them back to me, so I can help out more, but I remember thinking everything was pretty clear.
     
  11. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Ahh that one - I fixed that and closed it. If you have filed bugs with us, you get a URL in your reply mail which you can use to look at the status.
     
Thread Status:
Not open for further replies.