- Home /
App Crashes while creating a TextMesh game object in iOS device
I have a function that will create a game object with TextMesh component dynamically, the code is as the following:
// this will create a TextMesh game object in the passed parent transform
public static FlyingText getInstanceWithTextMesh(string text, Vector3 pos, int fontSize, Color color, float speed, float duration, Transform parentTransform) {
pos.z = parentTransform.position.z;
// create game object
GameObject obj = new GameObject ("FlyingText");
obj.transform.parent = parentTransform;
obj.transform.position = pos;
obj.transform.localScale = new Vector3 (1, 1, 1);
// add TextMesh component
TextMesh t = obj.AddComponent<TextMesh> (); // !!!!!!!!!! it will crash here !!!!!!!!!!!!!!
t.text = text;
t.alignment = TextAlignment.Center;
t.font = Resources.Load ("Fonts/"+Const.DEFAULT_FONT_NAME) as Font;
t.fontSize = fontSize;
t.color = color;
t.characterSize = 0.1f;
...
}
It will crash at this line every time 100%:
TextMesh t = obj.AddComponent ();
Here is the crash log in Xcode:
There is absolutely no problem when I tested in the PC emulator. It only happens in iOS device(Android seems not happen this). One more strange thing, If I insert a TextMesh game object by editor(not by script code) and test again. Then it won't crash any more. I absolutely don't know why....
Does anyone can help?
BTW, I am using Unity 5.2.1f1 and tested in iPhone 6, iOS 8.3.
Hi there,
I got hit with this crash as well with Unity 5.3.4 patch 5 and found your report. I submitted a bug report and gave them a sample project to Unity. They were able to reproduce and added that it is only affected when using IL2CPP backend.
Thanks.
Answer by Seed_user · May 11, 2016 at 08:18 AM
@firestoke -- got a reply back from Unity and not sure if this applies to you but it involves IL2CPP and code stripping.
My sample project sent to them involved nothing but a MonoBehaviour adding a TextMesh component in the Start() method. I built the sample with IL2CPP backend and code stripping enabled. Their code stripping routines determined that I didn't use that component as they don't scan source to determine what components you need.
Here's his suggestions for fixing (option 3 is my preferred choice):
We have three possible work arounds for this issue:
You can disable the "Strip Engine Code" option. This will increase the size of the output binary, but it is the simplest work around.
You can add a MeshRenderer component to a dummy game object in a scene which is part of the build. This will prevent the MeshRenderer component from being stripped.
You can use a link.xml file to tell the code stripping system to preserve the MeshRenderer component. This link.xml file worked for me:
<linker>
<assembly fullname="UnityEngine">
<type fullname="UnityEngine.MeshRenderer" preserve="all"/>
</assembly>
</linker>
More details about the link.xml file are available here: http://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html
Hope that helps.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
C# and JavaScript Unstable? 1 Answer
Distribute terrain in zones 3 Answers
WebCamTexture IOS crashing? 1 Answer
EDITED rend.material change too hard to handle for iOS 0 Answers