Unity3d报告奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.
其中使用了该项目.NET的Async Socket代码。后来不知道什么时候这个奇怪的错误的出现:
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.
怪异是由于报错并没有影响程序运行,而是正确地接收了server返回的信息,而且通过回调正确显示出来。说明回调被运行了。可是从回调再调用一个解析器却一直不运行。是不是上面的错误导致的?
搜索百度CompareBaseObjectsInternal关键词仅仅有8个结果,http://blog.csdn.net/jixuguo/article/details/26693977相对有些意义,可是博文为转载。后来看到原文,大致的意思是假设从子线程调用主线程的callback。须要给回调加一个interface。
这个和我的情况不太一样,參考意义不大。
然后google。非常不幸古大哥一直载入载入。
。。
于是去yahoo,竟然还没有抽筋。
最前面搜索出来的几篇文章就是unity论坛上的。大致看出一些眉目。
http://forum.unity3d.com/threads/comparebaseobjectsinternal-error.184069/#post-1258700
http://forum.unity3d.com/threads/comparebaseobjectsinternal-can-only-be-called-from-the-main-thread-annoying.195902/http://forum.unity3d.com/threads/comparebaseobjectsinternal-can-only-be-called-from-the-main-thread-annoying.195902/
分析出来我的问题大概是在主线程里面注冊了回调,
//注冊全部事件的响应代码
NetEventManager.GetInstance().netMessageReceived_event += OnNetMessageReceived;
NetEventManager.GetInstance().gateServerConnected_event += OnGateServerConnected;
NetEventManager.GetInstance().errorMessageOccured_event += OnErrorReceived;
然后socketclient对象是异步的,所以做了多线程处理,当socketclient接收到消息时,回调了主线程的函数(继承自monobehaviour),这时候就导致了报错。上面第一篇unity论坛博文解释得比較清楚,大概就是unity对于API调用主线程做了限制:
“Unity chose to limit API calls to main-thread, to make a simple and solid threading model that everyone can understand and use.”
依据这个解释,我把上面的代码凝视掉。程序就不报错了。
预计这些事件响应代码要放到非monobehavior的类里面去。就能够避免上面说的线程安全问题。
因为我感兴趣的多线程编程的基本或白色,上面的解释是正确的、有没有更好的解决办法。也希望你有种。
版权声明:本文博主原创文章。博客,未经同意不得转载。
Unity3d报告奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.的更多相关文章
- Error: CompareBaseObjectsInternal can only be called from the main thread
Posted: 01:39 PM 06-17-2013 hi, we're working on a project where we need to do some calculations on ...
- could not build module 'XXXXXXXX'或者error: expected identifier or '(' 。一堆奇怪的错误————错误根源
一堆奇怪的错误:1⃣️could not build module 'XXXXXXXX' 2⃣️error: expected identifier or '(' 3⃣️EDIT Setting Pr ...
- Unity3d导入工程出现错误“Creating unique file”的解决方法
Unity3d导入工程出现错误“Creating unique file:creating file Temp/tempFile failed.Please ensure there is enoug ...
- .net操作oracle,一定要用管理员身份运行 visual studio 啊,切记切记,免得报奇怪的错误。
.net操作oracle,一定要用管理员身份运行 visual studio 啊,切记切记,免得报奇怪的错误.
- Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出
Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出 package com.test; import org.apach ...
- 请教前辈:关于JS的一个奇怪的错误,不知是解析顺序造成的,还是什么原因。。
各位前辈好,如题,不知道是HTML解析顺序造成的,还是JS预编译的结果(见注释). 烦请各位前辈进行指导. <!DOCTYPE html> <html> <head> ...
- celery 错误相关:Monkey-patching not on the main thread; threading.main_thread().join() will hang from a greenlet
/Users/wangpingyang/.pyenv/versions/3.7.2/lib/python3.7/site-packages/httprunner/__init__.py:5: Monk ...
- [原]Unity3d中奇怪的编译错误
整理项目,重新build时出现一些问题,这些代码在原项目中都是可以运行的. 错误信息如下: Assets/XXXXX.cs(79,35): error CS0103: The name `NNNNNN ...
- Java错误:很奇怪的错误。。。
刚刚调试java web中出现了一个很奇怪的现象,前端有一个页面通过ajax调用后台的servlet,当我把后台的servlet代码修改后(将返回值由a修改为b),前端页面仍然获取的是a.调试跟踪se ...
随机推荐
- python3中sum
摘自https://blog.csdn.net/ikerpeng/article/details/17026011 其实python中sum有两种 一种是python自己的sum 另一种是python ...
- 关于Altium Designer重新修改某一原件pcb封装的问题
在重新导入的时候可能会影响到类class,所以可能是原理图中没有类吧 上图中的comment的修改是表示下面图片中的 comment栏的改变:
- 10.11 android输入系统_补充知识_activity_window_decor_view关系
android里:1个application, 有1个或多个activity(比如支付宝有:首页.财富.口碑.朋友.我的,这些就是activity)1个activity, 有1个window(每个ac ...
- 9.7 Binder系统_c++实现_编写程序
参考文件:frameworks\av\include\media\IMediaPlayerService.h (IMediaPlayerService,BnMediaPlayerService)fra ...
- 10、V4L2摄像头获取单幅图片测试程序(MMAP模式)
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h> ...
- 【微信小程序】自定义模态框实例
原文链接:https://mp.weixin.qq.com/s/23wPVFUGY-lsTiQBtUdhXA 1 概述 由于官方API提供的显示模态弹窗,只能简单地显示文字内容,不能对对话框内容进行自 ...
- 在此页上的 ActiveX 控件和本页上的其它部份的交互可能不安全
版权声明:转载时请以超链接形式标明文章原始出处和作者信息http://xqy266.blogbus.com/logs/66258230.html 在EOS6的项目中,如果采用VC++开发的Active ...
- 【例题3-5 UVA - 1583】Digit Generator
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] for (int i = 1;i <= n;i++) { 算出i是哪一个的生成元. 假设是y. 则ans[y] = min(a ...
- Nutch关于robot.txt的处理 分类: H3_NUTCH 2015-01-28 11:20 472人阅读 评论(0) 收藏
在nutch中,默认情况下尊重robot.txt的配置,同时不提供配置项以忽略robot.txt. 以下是其中一个解释.即作为apache的一个开源项目,必须遵循某些规定,同时由于开放了源代码,可以简 ...
- wPaint在线绘图插件
wPaint在线绘图插件 一.总结 一句话总结: 1.搜画图插件的时候关键词应该搜什么? jquery画图插件 js画图插件 jquery绘图插件 这些 二.在线绘图插件--wPaint 的实际应用 ...