Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
游戏中出现CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.的错误,经过分析是因为在某个非主线程地方使用了Unity API,即在某处非主线程对Unity内置类型的实例使用了!=,由于这个某处非常不好查找,Unity编辑器没有给出代码的具体定位,所以对所有Unity的内置类型实例的!=比较,统一替换为.Net自带函数的System.Object.ReferenceEquals来比较,经过测试,无论客户端采用多线程还是单线程运行,都不会再出现上述CompareBaseObjectsInternal错误。详细分析见:http://jiangyunfan2015.blog.163.com/blog/static/2483780502015410103446319.
游戏原来的错误,截图1。
该错误是由某个在非主线程的代码对Unity的内置类型实例使用了【!=】引起,但是这个某处很难找到,
截图中的红箭头表示类似的代码,不是指就是这处引发的,因为Unity编辑器没有给出具体提示。
截图1
把脚本中对所有Unity的内置类型实例的!=比较,统一替换为.Net自带函数的System.Object.ReferenceEquals来比较之后,游戏运行没有出现CompareBaseObjectsInternal的错误。见截图2.
截图2