Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CanvasScalerWithChildTextObjectDoesNotCrash.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine;
  2. using UnityEngine.TestTools;
  3. using NUnit.Framework;
  4. using System.Collections;
  5. using UnityEngine.UI;
  6. [TestFixture]
  7. [Category("RegressionTest")]
  8. [Description("CoveredBugID = 734299")]
  9. public class CanvasScalerWithChildTextObjectDoesNotCrash
  10. {
  11. GameObject m_CanvasObject;
  12. [SetUp]
  13. public void TestSetup()
  14. {
  15. #if UNITY_EDITOR
  16. UnityEditor.EditorApplication.ExecuteMenuItem("Window/General/Game");
  17. #endif
  18. }
  19. [UnityTest]
  20. public IEnumerator CanvasScalerWithChildTextObjectWithTextFontDoesNotCrash()
  21. {
  22. //This adds a Canvas component as well
  23. m_CanvasObject = new GameObject("Canvas");
  24. var canvasScaler = m_CanvasObject.AddComponent<CanvasScaler>();
  25. m_CanvasObject.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceCamera;
  26. //the crash only reproduces if the text component is a child of the game object
  27. //that has the CanvasScaler component and if it has an actual font and text set
  28. var textObject = new GameObject("Text").AddComponent<UnityEngine.UI.Text>();
  29. textObject.font = Font.CreateDynamicFontFromOSFont("Arial", 14);
  30. textObject.text = "New Text";
  31. textObject.transform.SetParent(m_CanvasObject.transform);
  32. canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
  33. canvasScaler.referenceResolution = new Vector2(1080, 1020);
  34. //The crash happens when setting the referenceResolution to a small value
  35. canvasScaler.referenceResolution = new Vector2(9, 9);
  36. //We need to wait a few milliseconds for the crash to happen, otherwise Debug.Log will
  37. //get executed and the test will pass
  38. yield return new WaitForSeconds(0.1f);
  39. Assert.That(true);
  40. }
  41. [TearDown]
  42. public void TearDown()
  43. {
  44. GameObject.DestroyImmediate(m_CanvasObject);
  45. }
  46. }