hi, we’re working on a project where we need to do some calculations on a separate thread. The data we need for the calculations is stored on a scriptable object. We use the scriptable object so that we can
serialize the data and save it as an asset file. However, when we tried to access the data from a separate thread we get the following error. 





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.







For our purposes we only need to read the data. One of the things that we tried to do to get around this was to use an interface. It appears that if you use an interface as a reference to the object then you’re able to access the data without getting that error.
For example

Code:  
  1. public class Node : ScriptableObject
  2.  {
  3.         public int[] data;
  4.  }
  5.  
  6. List<Node> dataset;
  7. ..
  8.  
  9. // Error, this fails inside of thread
  10. Node node = dataset[i];

this works:

Code:  
  1. public interface INodeData
  2.  {
  3.         int[] data { get; }    
  4.  }
  5.  
  6. public class Node : ScriptableObject, INodeData
  7.  {
  8.         public int[] data;
  9.  }
  10.  
  11. List<INodeData> dataset;
  12. ..
  13.  
  14. // this works! inside of thread
  15. INodeData node = dataset[i];

Error: CompareBaseObjectsInternal can only be called from the main thread的更多相关文章

  1. Unity3d报告奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.

    其中使用了该项目.NET的Async Socket代码.后来不知道什么时候这个奇怪的错误的出现: CompareBaseObjectsInternal can only be called from ...

  2. [原]openstack-kilo--issue(十九) ImportError: Could not import settings 'openstack_dashboard.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named main

    查看此问题的时候请先查看 这个问题包含在(十)中,此篇只是从(十)中分离出来 openstack-kilo--issue(十)ERROR: openstack Unable to establish ...

  3. [java] [error] java.lang.OutOfMemoryError: unable to create new native thread

    前言 最近公司的服务器出现了oom的报错,经过一番排查,终于找到了原因.写下这篇博客是为了记录下查找的过程,也是为了帮助那些跟我门遇到的情况相同的人可以更快的寻找到答案. 环境 系统:linux(ce ...

  4. Unity 中 使用c#线程

    使用条件   天下没有免费的午餐,在我使用unity的那一刻,我就感觉到不自在,因为开源所以不知道底层实现,如果只是简单的做点简单游戏,那就无所谓的了,但真正用到实际地方的时候,就会发现一个挨着一个坑 ...

  5. SFTP &amp; FTP Upload

    简述 >> FTP: 1. Install FTP service on Linux(Red Hat) as root user    [root]# yum install ftp 2. ...

  6. CompletableFuture的使用例子

    1. CompletableFuture的介绍 在Java8时被引入,在包java.util.concurrent下,是Java多线程编程中的一个类,扩展了Future中很多功能,Completabl ...

  7. 【Linux】关于Linux的系统编程总结

    作者:李春港 出处:https://www.cnblogs.com/lcgbk/p/14673383.html 目录 系统编程 (一)进程 1.进程的概念 2.进程函数接口 (1)fork()在进程内 ...

  8. error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用

    MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用 Debug ...

  9. MSVCRTD.lib(mfc.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainC (转)

    一.问题描述 我所使用的编程环境:VS2010 出现的问题如下: MSVCRTD.lib(mfc.obj) : error LNK2019: 无法解析的外部符号_WinMain@16,该符号在函数 _ ...

随机推荐

  1. 【撸码caffe 一】syncedmen.hpp

    SyncedMemory类主要负责在主机(CPU)和设备(GPU)之间管理内存分配和数据同步工作,封装了CPU和GPU之间的数据交互操作. 补充一点GPU的相关知识: 对CUDA架构而言,主机端的内存 ...

  2. (Go)01.Windows 安装 Go语言开发环境以及使用

    一.Go语言下载 go语言官方下载地址:https://golang.org/dl/ 找到适合你系统的版本下载,本人下载的是windows msi版本.也可以下载Source自己更深层次研究go语言 ...

  3. 线上出bug了?别怕,这么定位!

    摘要: Source Map还是很神奇的. 原文:线上出bug了?别怕,这么定位! 公众号:前端小苑 Fundebug经授权转载并修改,版权归原作者所有. 工作中,生产环境代码是编译后代码,搜集到报错 ...

  4. rehat7.X下postgresql 11编译安装

    文档目录结构: 一.准备 操作系统版本:rehat7.6 Postgresql:11.2 软件安装目录:/pgsql11/basedir 数据文件存放目录:/pgsql11data/ 11.2的下载地 ...

  5. 导入Excel时去除多余的空白行

    https://blog.csdn.net/shuishousuiyue/article/details/44773987 按着上面链接用的第一种方式,如下图所示:第二种方式要遍历每一个Excel单元 ...

  6. JavaScript Cookies使用

    Cookie 是个存储在客户端(浏览器)记录信息确定用户身份的小文本文件,可以用来跟踪用户当前登陆状态和用户浏览页面的次数,记录用户输入的文本信息,也可以在页面间传递变量,记录用户一些行为. 当浏览器 ...

  7. python的小数据池和深浅拷贝

    小数据池 一种数据缓存机制,也称驻留机制 在同一代码块,相同的值不会开辟新的内存 特殊字符除外 小数据池只针对:在控制台时! 数字 :-5到256间的整数会被缓存 布尔值:都会缓存8 字符串 小于等于 ...

  8. C语言break/continue/exit/return的功能区别

    break是跳出整个循环而执行循环体之外的下一条语句: continue只是跳出本次循环继续判断下一次循环条件是否满足. exit() 结束当前进程/当前程式/,在整个程式中,只要调用 exit ,就 ...

  9. PhotoZoom Pro 7 支持哪些图像格式?

    PhotoZoom是一款新颖的.技术上具有革命性的对数码图片无损放大的工具.为设计工作者提供了优良的解决方案,可快速渲染出完美的放大照片,呈现无与伦比的画质效果.将因其应用的广泛性,所以对图像文件的支 ...

  10. Python基础:编码

    1:先说python2py2里默认编码是ascii文件开头那个编码声明是告诉解释这个代码的程序 以什么编码格式 把这段代码读入到内存,因为到了内存里,这段代码其实是以bytes二进制格式存的,不过即使 ...