Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复游戏中出现CompareBaseObjectsInternal的错误 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jyunfan2015
Copy link

游戏中出现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

03

把脚本中对所有Unity的内置类型实例的!=比较,统一替换为.Net自带函数的System.Object.ReferenceEquals来比较之后,游戏运行没有出现CompareBaseObjectsInternal的错误。见截图2.

截图2

04

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant