3

I'm experiencing a really weird bug using the latest version of unity and the IDE is visual studio 2015 community. I have a button which triggers a function when it's clicked and also sends a short string as a parameter. In the method I first check if the string is null or empty, and I run some code if that's the case else I run some other code (caption obvious).. The problem is that the parameter is neither null nor empty however the first condition is being triggered, I'm 100 % sure because I logged the result of the operation like this Debug.Log("elementType : " + elementType + " result : " + string.IsNullOrEmpty(elementType)); and it basically prints fire.. false also I ran debugger to make sure that the parameter is not empty but it got even weirder after the if condition got triggered the else statement also got triggered !

Here's a video where i show the problem : http://screencast.com/t/iRtXtQaMDh8K.

And here's a screenshot of the debug.log : http://prntscr.com/bv0xsg

I've tried restarting both Unity and visual studio but no with no luck. I also put a lock on the method in case somehow magically some other thread access the same method at the same time which is certainly not the case again no luck.

  • Could try the answer here but won't mark this as duplicate as the answer doesn't seem to have been accepted (http://stackoverflow.com/questions/17150131/string-isnullorempty-returns-true-when-supplied-string-is-not-null). Does it work if you separate the `Null` and `Empty` checks as two different checks as shown in the first edit of the question? – keyboardP Jul 20 '16 at 00:01
  • 2 Separate if statements fix the problem yes however if i put them in one if it still causes the bug. – GeekCodingMaster Jul 20 '16 at 00:17
  • It seems to be an interesting bug. Has it always been the case or was there a stage where the code was working fine? – keyboardP Jul 20 '16 at 00:21
  • Yes, I'm just switching from 2D to 3D in my previous project it is working fine even now, absolutely nothing is changed there but in the 3D one it just doesn't seems to work for some reason. – GeekCodingMaster Jul 20 '16 at 00:25
  • Why not post the Button's code that triggers this function? That might actually be the problem. – Programmer Jul 20 '16 at 01:55
  • It doesn't have any code, I'm using unity's event trigger's http://prntscr.com/bv5uqy – GeekCodingMaster Jul 20 '16 at 09:20
  • @GeekCodingMaster - May want to keep an eye on this thread too. Not 100% sure but seems related to your issue http://stackoverflow.com/questions/38486959/nullreferenceexception-when-reading-a-string-while-debugging-or-running-normall – keyboardP Jul 20 '16 at 18:48
  • Can you post more code, especially around the code that is breaking? – Nabren Apr 16 '17 at 22:31

0 Answers0