Author Topic: UIWrapContent and Streamreader.  (Read 5095 times)

pcutile

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 81
    • View Profile
UIWrapContent and Streamreader.
« on: June 30, 2017, 09:30:35 AM »
I dont' know if title of the post is correct to 100% but this is my problem.
i have a class that load a text file, the name of the file is inside a variable (we say ie filename) and a funtion LoadText, load regular text file (made of strings that  end with "\n"
  • ).

So if i use a button that work with OnCLick to call LoadText after changing the filename inside my class, well it load the text file normally, but if i put this button inside a UIWrapContent (because i need several button inside an endless scroll view) unity say ne when click:

ArgumentException: path contains invalid characters.

So for resume...this is LoadText

public void LoadText (string nome)
   {      
      Debug.Log (nome);
      if (sr != null)
         sr.Dispose ();
         sr = new StreamReader ("Assets/Resources/"+nome + ".txt");
         temp = sr.ReadToEnd ();
         sr.Close ();
         
         }
   //   prodwrap.GetComponent<UIWrapContent>().WrapContent();
      prodwrap.SetActive(true);
      
         
   }

if i use in start or on enable when the button is inside uiwrap IT WORK but at second click it give the error on line with new StreamReader. i f i use it on a button with parent UIRoot it works at 100%, can changing name at runnign and reload relative text file whitout problems..
I hope i'm clear..





ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIWrapContent and Streamreader.
« Reply #1 on: July 06, 2017, 05:42:25 AM »
Did you print your "nome"? Debug.Log it and see what it is. This isn't an NGUI issue.

pcutile

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 81
    • View Profile
Re: UIWrapContent and Streamreader.
« Reply #2 on: July 06, 2017, 08:38:46 PM »
yes it print every time and make error after on new streamreader..
for me it's related to ngui because if i use it under a button under uiroot it work every time, but if i use in a button inside endlessscrollviews it make this error when i call (less for Start..call it at start work).
i have created another project inside unity, and it always make this error. Other friends have tried my simple funziotn with button created with unity gui and don't retrieve any error.

Barsmin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIWrapContent and Streamreader.
« Reply #3 on: July 07, 2017, 09:46:33 AM »
Hey, I got the same problem, if you find something to solve it, can you give me the info too ? Thanks  :(

The webpage which on which this problem occurs is this one on ninjaunits.com: how much does a quart of water weigh. When you click the button, nothing happens.
« Last Edit: July 29, 2020, 10:28:25 AM by Barsmin »

pcutile

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 81
    • View Profile
Re: UIWrapContent and Streamreader.
« Reply #4 on: July 11, 2017, 07:30:43 PM »
Barsmin..no news??

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIWrapContent and Streamreader.
« Reply #5 on: July 15, 2017, 06:24:44 AM »
Post the full script so I can reproduce it on my end, because the only way I can see your function failing is if you pass an invalid value to it.

Also note that you are never setting "sr" back to null in your code after closing the stream. You need to set it to null because you check for null.

pcutile

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 81
    • View Profile
Re: UIWrapContent and Streamreader.
« Reply #6 on: July 15, 2017, 10:41:21 AM »
put a button that when clicked use loadtext mentioned above under uiroot work anytime make the same with a button that is inside an endless scrool view don't work. it's simply and clear and you know that another person have the same problem, so this time we are sure that all understood my concepts.

pcutile

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 81
    • View Profile
Re: UIWrapContent and Streamreader.
« Reply #7 on: July 19, 2017, 09:52:18 AM »
Aren Mook follow me..use a button that launch the code i showed in post.
error sure happens when you use dinamic button inside scroll view. In my program i use create a new scrollview (complete with uiwrapcontent etc etc but without elements) and put buttons (with nguitools.addchild..) that launch my procedure. if button is in scroll view from the beginning works otherwise it make error in question..
it's sure..consider it..


pcutile

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 81
    • View Profile
Re: UIWrapContent and Streamreader.
« Reply #8 on: July 19, 2017, 08:52:13 PM »
Ok ArenMook i find the issue. So consider that my LoadText function works well when i call first time with a button that is under UIroot. Problems was in filename convention, windows admit filename like "Cocktails.txt" but dos (and so even streamreader) wants only lowercase filename.
Error was not only in my works because from windows and in particular form cmd command line i can read for example c:\Cocktails.txt and more my UiButton at first time works even if namefile is with uppercase...
Thanks for help now it's all ok.