月度存档: 6月 2015

测试下unity中的异常在各平台上的表现

测试目的:

测试异常在android及ios64下的表现,查看是否导致闪退或崩溃。

测试代码:

	private void onclick1( ){
		Debug.Log("click1");
		int m=3;
		int n=0;
		Debug.Log(m/n);
	}
	private void onclick2( ){
		Debug.Log("click2");
		TestA test=null;
		Debug.Log(test.m);
	}

在unity editor中:

表现正常,没有导致app死掉。

在Android中:

可以在ddms中收集到异常,同时app没有崩溃。

在IOS中:

也是可以正常打出log及堆栈

发现也没有引起崩溃。

IOS上32位mono闪退的原因找到了:

解决方案:

http://developer.xamarin.com/guides/ios/troubleshooting/troubleshooting/

unity中计算使用的时间

基本上有几种方式

1、DateTime.UtcNow,性能好,速度快,但是精度低一此,10ms左右

2、第二种是用StopWatch,但是据称在多核多线程环境会有时有误差。

3、Process.GetCurrentProcess().TotalProcessorTime;时间准确度高,但相应的是性能较低下。可以使用宏定义,在测试版本中才开启,在正式发布版本中关闭这个功能。

噢,我们用时间,主要是用来埋点查看性能热点的地方。

fmod在ios64上无声音的问题

以前解决一个加载慢的问题时,发现fmod写的加载代码很差,尤其在android平台,做了很多无用功。

于是我就重写了fmod加载代码,使用www异步加载,加载的字节数组放在cache中,然后供fmod调用:

FMOD.RESULT result = FMOD_StudioSystem.sInstance.System.loadBankMemory(pair.Value,LOAD_BANK_FLAGS.NORMAL,out bank);

结果发现在ios上无法播放声音。

开始怀疑过il2cpp的问题,但是没有log,不能随便下定论。

添加过很多log后,定位到上面的函数出问题了,但是log中只记录执行到这里就没了。没有输出为什么错。

丝毫没有头绪后,在fmod官方发现有新版本了,下载新版本后,测试下,发现还是没有声音,但是至少有异常log了。

il2cpp暂时不支持从c/c++对c#进行调用,或者说至少不支持现在fmod的用法。

解决方法也很简单,修改为使用

	FMOD.RESULT result = FMOD_StudioSystem.instance.System.loadBankFile(bankPath, LOAD_BANK_FLAGS.NORMAL, out bank);

 

网上还有一个哥们遇到同样问题了,关注下看看他怎么解决。

http://forum.unity3d.com/threads/making-calls-from-c-to-c-with-il2cpp-instead-of-mono_runtime_invoke.295697/

 

看到一篇文件比较的unity下的各种调用的性能

http://forum.unity3d.com/threads/pinvoke-mono_add_internal_call-c-and-c.172886/

以备自己学习用。

这里还有一篇:http://www.snowbolt.com/index.php/blog/28-tech/91-pinvoke

目前看起来,mono要比c/c++慢一个数量级,lua又比mono慢一个数量级。

如果想要最好的性能,应该还是lua直接建在c/c++上,但是又如何去调用MonoBehaviour,如果能跳过mono,直接通过c/c++调用,则性能应该是最优的。但是需要确认下如何调用?

如果能实现,则是c/c++ + lua,直接跳过了 mono。

还有不确定的因素:il2cpp会不会可以直接实现这些性能提升?未来 需要确认下。

网上有位兄弟反编译的unity editor,看了下,不知道能否实现 lua 直接像调用c接口一样来调用MonoBehaviour.

namespace UnityEngine
{
    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;

    public class MonoBehaviour : Behaviour
    {
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern MonoBehaviour();
        public void CancelInvoke()
        {
            this.Internal_CancelInvokeAll();
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void CancelInvoke(string methodName);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private extern void Internal_CancelInvokeAll();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private extern bool Internal_IsInvokingAll();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void Invoke(string methodName, float time);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void InvokeRepeating(string methodName, float time, float repeatRate);
        public bool IsInvoking()
        {
            return this.Internal_IsInvokingAll();
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern bool IsInvoking(string methodName);
        public static void print(object message)
        {
            Debug.Log(message);
        }

        public Coroutine StartCoroutine(IEnumerator routine)
        {
            return this.StartCoroutine_Auto(routine);
        }

        public Coroutine StartCoroutine(string methodName)
        {
            object obj2 = null;
            return this.StartCoroutine(methodName, obj2);
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern Coroutine StartCoroutine(string methodName, object value);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern Coroutine StartCoroutine_Auto(IEnumerator routine);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void StopAllCoroutines();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void StopCoroutine(string methodName);

        public bool useGUILayout { [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall] get; [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall] set; }
    }
}

大计算量的代码,尽量避免使用c#代码,能用c/c++实现,就使用c/c++实现,然后暴露接口给c#层使用。

No matching provisioning profiles

这个错可能是证书或签名出问题了。

fmod ERR_HTTP_PROXY_AUTH

FMOD Error (ERR_HTTP_PROXY_AUTH): Proxy authentication is required to access the specified resource.
UnityEngine.Debug:LogWarning(Object)
FMOD.Studio.UnityUtil:LogWarning(String) (at Assets/Plugins/FMOD/FMOD_StudioSystem.cs:53)
FMOD.Studio.UnityUtil:ERRCHECK(RESULT) (at Assets/Plugins/FMOD/FMOD_StudioSystem.cs:120)
FMOD_StudioSystem:ERRCHECK(RESULT) (at Assets/Plugins/FMOD/FMOD_StudioSystem.cs:401)
FMOD_StudioSystem:Init() (at Assets/Plugins/FMOD/FMOD_StudioSystem.cs:274)
FMOD_StudioSystem:get_instance() (at Assets/Plugins/FMOD/FMOD_StudioSystem.cs:153)
TestLoading:Awake() (at Assets/scripts/config_model/TestLoading.cs:47)

这个错误之前遇到过一次。

这次遇到后忘记如何解决的了,白白费了半天工夫。这里记录下,免得自己又忘记了。

解决方式也很傻瓜式,把fmod的script及so,dll重新导入了一遍。


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /opt/wordpress/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048