EXEC BAD ACCESS - CSharp Script

Hey,
So I’m using the XMLParser by Jehu at the bottom of this post: http://forum.unity3d.com/threads/45447-XML-Parser-in-C?highlight=XML+Parser

I’ve put the XMLParse files into /Standard Assets (as it was complaining before), and it now works fine on the PC/Mac…

However when I install it on iPhone, it compiles, it runs… But when it comes to call the XMLParser code it crashes with an EXEC_BAD_ACCESS error…

Just wondering if there are some folder structure differences I need to adhere to when using unity iPhone, or something like that?

For ref, here is my code where it crashes:

	var tWWW = new WWW(<The URL to my XML File>);
	yield tWWW;
        EtceteraBinding.hideActivityView();
	if (tWWW.error != null) 
	{
	  	EtceteraBinding.showAlertWithTitleMessageAndButton( "Error getting Survey!", tWWW.error, "OK" );
	} 
	else 
	{

		parser=new XMLParser();
		var node=parser.Parse(tWWW.text);
		var val=node["Survey"][0]["details"][0]["@noOfQuestions"];
		var questionsToProcessFloat : float = float.Parse(val,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		questionsToProcess = questionsToProcessFloat;
		Debug.Log(questionsToProcess);
		
		for(var QuestionNo = 0;QuestionNo < questionsToProcess-1;QuestionNo++){
			questionIDArray[QuestionNo]=node["Survey"][0]["question"][QuestionNo]["@id"];
			questionTypeArray[QuestionNo]=node["Survey"][0]["question"][QuestionNo]["@type"];
			questionTextArray[QuestionNo]=node["Survey"][0]["question"][QuestionNo]["@questionText"];
			questionOptionsArray[QuestionNo]=node["Survey"][0]["question"][QuestionNo]["@options"];
			questionRepliesArray[QuestionNo] = "";
			multiChoiceArray[QuestionNo] = 0;
		}

As mentioned, it works 100% fine on PC, just need to figure out the iPhone issue :).

Cheers,

  • Adam G

This code is Javascript and not C# script. I would be willing to bet that somewhere in that hierarchy you aren’t defining your types. Unity’s iPhone compiler will let that go but you will end up with a null for that instance. For example if you do:

private var parser;

instead of

private var parser : XMLParser;

you will fail every time. It will work on the PC fine because it doesn’t have the constraint of not using dynamic types. The iPhone does NOT support this and you’ll have to tweak your scripts accordingly.

Mmm ok,
I’ve changed the code to the following:

        EtceteraBinding.showBezelActivityViewWithLabel("Loading Survey");
	var tWWW = new WWW("http://www.dailyappdream.com/ExampleXML_Survey3.xml");
	yield tWWW;
		EtceteraBinding.hideActivityView();
	if (tWWW.error != null) 
	{
	 	EtceteraBinding.showAlertWithTitleMessageAndButton( "Error getting Survey!", tWWW.error, "OK" );
	} 
	else 
	{
		
		var parser : XMLParser = new XMLParser();
		var node  : XMLNode = parser.Parse(tWWW.text);
		var val = node["Survey"][0]["details"][0]["@noOfQuestions"];
		var questionsToProcessFloat : float = float.Parse(val,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		questionsToProcess = questionsToProcessFloat;
		Debug.Log(questionsToProcess);
		
		for(var QuestionNo = 0;QuestionNo < questionsToProcess-1;QuestionNo++){
			questionIDArray[QuestionNo]=node["Survey"][0]["question"][QuestionNo]["@id"];
			questionTypeArray[QuestionNo]=node["Survey"][0]["question"][QuestionNo]["@type"];
			questionTextArray[QuestionNo]=node["Survey"][0]["question"][QuestionNo]["@questionText"];
			questionOptionsArray[QuestionNo]=node["Survey"][0]["question"][QuestionNo]["@options"];
			questionRepliesArray[QuestionNo] = "";
			multiChoiceArray[QuestionNo] = 0;
		}

This still works on the PC, and it no longer causes an EXEC_BAD_ACCESS crash on the device, however nor does it load the survey like it should. Anyone got any ideas/ can anyone point out anything I’m doing blatantly wrong?

Cheers,

  • Adam G

Ok I think it has something to do with how I’m accessing the arrays based on what it says here: http://forum.unity3d.com/threads/17089-Type-Object-does-not-support-slicing-(error)

What I’m struggling with is how I should be structuring the line “var val = node[“Survey”][0][“details”][0][”@noOfQuestions"];" so it will work?

Ok, I’ll pay $30 via paypal to anyone who can quickly make this work if I ping over the scripts?
If interested then just post as I need it sorting fairly urgently…

Cheers,

  • Adam G

ok, nevermind - think I’ve worked it out myself :).

Edit - Fixed it :)!

You should post what it is some that people coming behind you see what the fix was.

Javascript version of the parser + this format to access the XML:

var val = ((((node[“Survey”] as Array)[0] as Hashtable)[“details”] as Array)[0] as Hashtable)[“@noOfQuestions”];