Quantcast
Channel: Questions in topic: "xcode"
Viewing all articles
Browse latest Browse all 1047

Xcode Problem (Whats Wrong With My Code)

$
0
0
So we are creating a scratch card type effect in our app. This app is already out on android and the effect is working perfect. Now we are trying to get it on iPhone, but we keep running into a error with the scratch card effect on Xcode. It works on Unity editor and on Unity Remote for IOS but it won't do the effect when on the device alone. Heres our Scratch Card Effect code. The build is always successful, the scratch card effect just does not work. using UnityEngine; using System.Collections; public enum RefreshRate { _10_FPS = 10, _20_FPS = 20, _30_FPS = 30, _40_FPS = 40, _50_FPS = 50, _60_FPS = 60, } public class ScratchIt : MonoBehaviour { public bool interpolateMovement = true; public int brushSize = 30; public RefreshRate refreshRate = RefreshRate._30_FPS; [SerializeField, Range(10, 500)] int maxCycleByInterpolation = 100; [SerializeField, Range(1, 10)] int alphaCheckPrecision = 5; [SerializeField] float scratchCompleted; public float ScratchCompleted { get {return scratchCompleted;} } Color[] brush; Color32[] data; Texture2D tex; float timer; Vector2 oldPosition; RenderTexture rt; Texture2D current; void Start () { oldPosition = Vector2.zero; timer = 0; current = renderer.material.GetTexture(0) as Texture2D; ResetCovering(); int tabSize = current.width * current.height; brush = new Color[tabSize]; for (int i = 0; i < tabSize; i++) brush[i] = new Color(0, 0, 0, 0); } /// /// Resets the covering. The image goes back to it's original texture /// public void ResetCovering() { data = current.GetPixels32(); Texture2D newTex = new Texture2D(current.width, current.height); newTex.SetPixels32(data); renderer.material.SetTexture(0, newTex); tex = newTex; tex.Apply(); updatePercentage(); } void Update () { if (ScratchCompleted >= 0.6) { Debug.Log("YOU WON!!"); } timer += Time.deltaTime; if (Input.GetMouseButton(0)) { Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Physics.Raycast(r, out hit); try { if (hit.collider.gameObject == this.gameObject) { if (!interpolateMovement) scratch(new Vector2(hit.textureCoord.x * tex.width, hit.textureCoord.y * tex.height)); if (timer > (1f / (float)refreshRate)) { if (interpolateMovement) scratch(new Vector2(hit.textureCoord.x * tex.width, hit.textureCoord.y * tex.height)); updatePercentage(); tex.Apply(); timer = 0; } } } catch { } } } public void updatePercentage() { Color32[] tmp = tex.GetPixels32(); // __________ SLOW __________ float value = 0; for (int i = 0; i < tmp.Length; i += alphaCheckPrecision) value += tmp[i].a; scratchCompleted = 1 - value / (255 * data.Length / 5); } void scratchInterpolated(Vector2 position) { if (Input.GetMouseButtonDown(0)) oldPosition = position; int i = 0; Vector2 tmpPos = oldPosition; Vector2 dir = (position - tmpPos).normalized; if (Vector2.Distance(tmpPos, position) > maxCycleByInterpolation) { oldPosition = position; } else while (Vector2.Distance(tmpPos, position) > 2) { oldPosition = position; scratchPoint(tmpPos); tmpPos += dir; i++; if (i > maxCycleByInterpolation) { break; } } } public void scratchPoint(Vector2 position) { Vector2 tmpPos = position - new Vector2(brushSize / 2, brushSize / 2); Vector2 cl = new Vector2((tmpPos.x + brushSize) - tex.width, (tmpPos.y + brushSize) - tex.height); tmpPos = new Vector2(Mathf.Clamp(tmpPos.x, 0f, tmpPos.x), Mathf.Clamp(tmpPos.y, 0f, tmpPos.y)); Vector2 tmpBrushSize = new Vector2(Mathf.Clamp(brushSize, 0, brushSize - cl.x + 1), Mathf.Clamp(brushSize, 0, brushSize - cl.y + 1)); if (tmpPos.x <= 0) tmpBrushSize.x = position.x + brushSize / 2; if (tmpPos.y <= 0) tmpBrushSize.y = position.y + brushSize / 2; tex.SetPixels((int)tmpPos.x, (int)tmpPos.y, (int)tmpBrushSize.x, (int)tmpBrushSize.y, brush, 0); } /// /// Scratchs main method. be careful, This method will scratch with interpolation if it's activated /// See the "interpolate" attribute /// /// Position, x:y on the texture public void scratch(Vector2 position) { if (interpolateMovement) scratchInterpolated(position); else scratchPoint(position); } public void scratch(Vector3 position) { scratch(new Vector2((int)position.x, (int)position.y)); } } On the Xcode Debugger it says the error is in our Assembly-CSharp.dll.s and the error it says is EXC_BAD_ACCESS (code=1, address = 0x0) When we further debugged it, we pin pointed the code breaking when it reaches the public void ResetCovering() and hits the data = current.GetPixels32(); line. Is GetPixels not readable by Xcode? Anything look wrong in my code? Is there a framework I am missing?

Viewing all articles
Browse latest Browse all 1047

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>