Error “Cast from pointer to smaller type 'int' loses information” in EAGLView.mm when update Xcode to 5.1 (5B130a)

Yesterday, I updated Xcode to the newest version (5.1 (5B130a)) to compatible with iOS 7.1. Then I build my project, I get the error "Cast from pointer to smaller type 'int' loses information" in EAGLView.mm file (line 408) when 64-bit simulators (e.g.: iPhone Retina 4-inch 64-bit) is selected.

I'm using cocos2d-x-2.2.2. Before I update Xcode, my project still can build and run normally with all devices.

Thanks for all recommendation.

Update: Today, i download the latest version of cocos2d-x (cocos2d-x 2.2.3). But the problem has still happened.

Here is some piece of code where that error occur:

/cocos2d-x-2.2.2/cocos2dx/platform/ios/EAGLView.mm:408:18: Cast from pointer to smaller type 'int' loses information

// Pass the touches to the superview
#pragma mark EAGLView - Touch Delegate
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    if (isKeyboardShown_)
        [self handleTouchesAfterKeyboardShow];

    int ids[IOS_MAX_TOUCHES_COUNT] = {0};
    float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
    float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};

    int i = 0;
    for (UITouch *touch in touches) {
        ids[i] = (int)touch;     // error occur here
        xs[i] = [touch locationInView: [touch view]].x * view.contentScaleFactor;;
        ys[i] = [touch locationInView: [touch view]].y * view.contentScaleFactor;;
    cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesBegin(i, ids, xs, ys);


Apparently the clang version in Xcode 5.1 and above is more strict about potential 32bit vs. 64 bit incompatibilities in source code than older clang versions have been. To be honest, I think, clang is too restrictive here. A sane compiler may throw a warning on lines like this but by no way it should throw an error, because this code is NOT wrong, it is just potentially error-prone, but can be perfectly valid.

The original code is

ids[i] = (int)touch;

with ids being an array of ints and touch being a pointer.

In a 64bit build a pointer is 64bit (contrary to a 32bit build, where it is 32bit), while an int is 32bit, so this assignment stores a 64bit value in a 32bit storage, which may result in a loss of information.

Therefore it is perfectly valid for the compiler to throw an error for a line like

ids[i] = touch;

However the actual code in question contains an explicit c-style cast to int. This explicit cast clearly tells the compiler "Shut up, I know that this code does not look correct, but I do know what I am doing".

So the compiler is very picky here and the correct solution to make the code compile again and still let it show the exact same behavior like in Xcode 5.0 is to first cast to an integer type with a size that matches the one of a pointer and to then do a second cast to the int that we actually want:

ids[i] = (int)(size_t)touch;

I am using size_t here, because it is always having the same size as a pointer, no matter the platform. A long long would not work for 32bit systems and a long would not work for 64 bit Windows (while 64bit Unix and Unix-like systems like OS X use the LP64 data model, in which a long is 64bit, 64bit Windows uses the LLP64 data model, in which a long has a size of 32bit (http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models)).

I meet this problem too.

ids[i] = (int)touch; // error occur here => I change this to below.

ids[i] = (uintptr_t)touch;

Then i can continue compiling. Maybe you can try this too.

XCode 5.1 is change all architecture to 64 bit.

you can just change architecture to support 32 bit compilation by all below in in Build Settings

  • use $(ARCHS_STANDARD_32_BIT) at Architecture instead of $(ARCHS_STANDARD)
  • remove arm64 at Valid Architectures

Hope it helps.

Surely the solution is to change the type of ids from int to type that is sufficiently large to hold a pointer.

I'm unfamiliar with XCode, but the solution should be something like follows:

Change the declaration of ids to:

intptr_t ids[IOS_MAX_TOUCHES_COUNT];

and the line producing the error to:

ids[i] = (intptr_t)touch;

Most of the "solutions" above can lose part of the pointer address when casting to a smaller type. If the value is ever used as pointer again that will prove to be an extremely bad idea.

You can fix this error by replacing this line of code.

ids[i] = (uint64_t)touch;

You should perform type conversion based on 64bit build system because the type "int" supports only -32768 ~ 32768.

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

  • error LNK2005: xxx already defined in MSVCRT.lib(MSVCR100.dll) C:\something\LIBCMT.lib(setlocal.obj)
    I'm using DCMTK library for reading Dicom files (Image format used in medical image processing.) I'm having a problem in compiling this DCMTK source code. DCMTK uses some additional external libraries (zlib, tiff, libpng, libxml2, libiconv). I know that all libraries should be generated with same Code Generation Options. I've downloaded the compiled versions of these support libraries which are compiled with "Multithreaded DLL" runtime options (/MD). In each project of DCMTK source code I ensured that runtime options are "Multithreaded DLL" (/MD). But still I'm getting these errors: Error 238
  • 错误LNK2005:MSVCRT.lib(MSVCR100.dll)中已定义的xxx C:\ something \ LIBCMT.lib(setlocal.obj)(error LNK2005: xxx already defined in MSVCRT.lib(MSVCR100.dll) C:\something\LIBCMT.lib(setlocal.obj))
    问题 我正在使用DCMTK库读取Dicom文件(医学图像处理中使用的图像格式。)在编译此DCMTK源代码时遇到问题。 DCMTK使用其他一些外部库(zlib,tiff,libpng,libxml2,libiconv)。 我知道所有库都应使用相同的代码生成选项来生成。 我已经下载了这些支持库的编译版本,这些支持库是使用“多线程DLL”运行时选项(/ MD)编译的。 在DCMTK源代码的每个项目中,我确保运行时选项为“多线程DLL”(/ MD)。 但仍然出现以下错误: Error 238 error LNK2005: ___iob_func already defined in MSVCRT.lib(MSVCR100.dll) C:\dcmtk-3.5.4-src\CMakeBinaries\dcmpstat\apps\LIBCMT.lib(_file.obj) dcmp2pgm Error 239 error LNK2005: __lock_file already defined in MSVCRT.lib(MSVCR100.dll) C:\dcmtk-3.5.4-src\CMakeBinaries\dcmpstat\apps\LIBCMT.lib(_file.obj) dcmp2pgm Error 240 error LNK2005: __unlock_file already
  • 运行ride.py报错
    报错信息如下: F:\Python3.8\Scripts>python ride.py <class 'robotide.preferences.configobj.UnreprError'> Parse error in value at line 0. <class 'robotide.preferences.configobj.UnreprError'> Parse error in value at line 3. <class 'robotide.preferences.configobj.UnreprError'> Parse error in value at line 4. <class 'robotide.preferences.configobj.UnreprError'> Parse error in value at line 5. <class 'robotide.preferences.configobj.UnreprError'> Parse error in value at line 6. <class 'robotide.preferences.configobj.UnreprError'> Parse error in value at line 7. <class 'robotide.preferences.configobj
  • robotframework安装与运行(ride.py1.7.4.2命令报错)(win10+python3.8.1)
    首先,robotframework必须在python的环境下运行 所以你的电脑里必须有python3.x的环境先。 上古时期的robotframework只支持python2,不过python2都已经停止更新和维护了,它也只能放下身段也支持python3了,它的前世今生就不在此过多赘述了。 接下来就是安装相关的库了。 通过pip命令直接安装。 pip install robotframework pip install Pypubsub==3.3.0 pip install wxPython==4.0.3 pip install robotframework-ride 最后通过pip list命令来查看已安装的库。 ps:如果pip命令安装过慢或直接就安装失败,可以使用国内镜像安装,参考:https://zhuanlan.zhihu.com/p/61696526 最后一步就是输入命令ride.py,打开RIDE界面了。 但是我在这一步遇到了报错,具体如下: <class 'robotide.preferences.configobj.UnreprError'> Parse error in value at line 0. <class 'robotide.preferences.configobj.UnreprError'> Parse error in value at
  • Angular 6 many Can't resolve errors (crypto, fs, http, https, net, path, stream, tls, zlib)
    I'm building an Angular 6 app, but every time I want to serve to localhost, I get these errors: ERROR in ./node_modules/aws-sign2/index.js Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\aws-sign2' ERROR in ./node_modules/aws4/aws4.js Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\aws4' ERROR in ./node_modules/ecc-jsbn/index.js Module not found: Error: Can't resolve 'crypto' in 'C:\Users\sorou\projects\tunrWeb\node_modules\ecc-jsbn' ERROR in ./node_modules/http-signature/lib/signer.js Module not
  • 在C#中使用身份验证复制文件(copy files with authentication in c#)
    问题 我正在尝试将文件从本地驱动器复制到服务器上的文件夹之一。 服务器上的文件夹名称为“ DBFiles”。 除了用户名“ user”和密码“ password1!”之外,没有人可以访问此功能。 在处理文件之前,它还会创建目录(如果不存在的话)。 可以在创建目录“测试”并复制文件时帮助获得访问权限。 if (!Directory.Exists(@"\\server-a\copiedfiles\")) Directory.CreateDirectory(@"\\server-a\DBFiles\"+Test); File.Copy("C:\Temp\abc.txt", @"\\server-a\DBFiles\"); 这是c#中的原始代码。 NetworkShare.DisconnectFromShare(@"\\server-a\DBFiles", true); //Disconnect in case we are currently connected with our credentials; NetworkShare.ConnectToShare(@"\\server-a\DBFiles", "user1", "password1!"); //Connect with the new credentials File.Copy(@"c:\temp\T1.txt", @"\
  • “ on error goto 0”和“ on error goto -1”之间的区别— VBA(Difference between 'on error goto 0' and 'on error goto -1' — VBA)
    问题 谁能在VBA中找到“ On error goto -1”和“ on error goto 0”之间的区别? 我已经尝试过Google和msdn,但是我没有运气。 回答1 On Error GoTo 0将禁用该过程中当前存在的任何错误捕获。 On Error GoTo -1清除错误处理并将其设置为空,这使您可以创建另一个错误陷阱。 示例:On Error GoTo -1(发生错误时转到-1) 引发第一个错误后,它将GoTo ErrorFound ,它将清除例程的错误处理并设置一个新错误,当发现错误时,它将GoTo AnotherErrorFound 。 Sub OnErrorGotoMinusOneTest() On Error GoTo ErrorFound Err.Raise Number:=9999, Description:="Forced Error" Exit Sub ErrorFound: On Error GoTo -1 'Clear the current error handling On Error GoTo AnotherErrorFound 'Set a new one Err.Raise Number:=10000, Description:="Another Forced Error" AnotherErrorFound: 'Code here
  • Pyaudio installation error - 'command 'gcc' failed with exit status 1'
    I'm running Ubuntu 11.04, Python 2.7.1 and wanted to install Pyaudio. So I ran, $ sudo easy_install pyaudio in the terminal and the process exited with following error messages, Searching for pyaudio Reading http://pypi.python.org/simple/pyaudio/ Reading http://people.csail.mit.edu/hubert/pyaudio/ Best match: pyaudio 0.2.4 Downloading http://people.csail.mit.edu/hubert/pyaudio/packages/pyaudio-0.2.4.tar.gz Processing pyaudio-0.2.4.tar.gz Running PyAudio-0.2.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-0Tetss/PyAudio-0.2.4/egg-dist-tmp-PYy9T8 In file included from /usr/include/python2.7
  • GetLastError返回值大全(英文最新版)(错误码0-1000)
    行数格式说明第一行VS枚举宏定义第二行错误码第三行错误原因ERROR_SUCCESS 0 (0x0) The operation completed successfully. ERROR_INVALID_FUNCTION 1 (0x1) Incorrect function. ERROR_FILE_NOT_FOUND 2 (0x2) The system cannot find the file specified. ERROR_PATH_NOT_FOUND 3 (0x3) The system cannot find the path specified. ERROR_TOO_MANY_OPEN_FILES 4 (0x4) The system cannot open the file. ERROR_ACCESS_DENIED 5 (0x5) Access is denied. ERROR_INVALID_HANDLE 6 (0x6) The handle is invalid. ERROR_ARENA_TRASHED 7 (0x7) The storage control blocks were destroyed. ERROR_NOT_ENOUGH_MEMORY 8 (0x8) Not enough storage is available to process this
  • Publish one web project from solution with msbuild
    I'm trying to deploy one of the web projects in my solution to a server. I am using msbuild on TeamCity like so: msbuild MySolution.sln /t:WebSite:Rebuild /p:DeployOnBuild=True /p:PublishProfile=Prod ... However, when I run it, msbuild still tries to build my WebService project, even though my WebSite project does not depend on it (but it does depend on a Services project also in the solution). How do only publish one project, aka just WebSite? I have also tried building the project file using msbuild WebSite/WebSite.csproj /p:DeployOnBuild=True ... but it then complains that it can't restore
  • 如何在web.xml中指定默认错误页面?(How to specify the default error page in web.xml?)
    问题 当用户遇到某些错误(例如,代码为404的错误)时,我在web.xml中使用<error-page>元素指定友好错误页面: <error-page> <error-code>404</error-code> <location>/Error404.html</location> </error-page> 但是,我希望如果用户不符合<error-page>指定的任何错误代码,则他或她应该看到默认的错误页面。 我该如何使用web.xml中的元素呢? 回答1 在Servlet 3.0或更高版本上,您只需指定 <web-app ...> <error-page> <location>/general-error.html</location> </error-page> </web-app> 但是,由于您仍在使用Servlet 2.5,因此别无其他选择,只能分别指定每个常见的HTTP错误。 您需要确定最终用户可能遇到的HTTP错误。 在使用HTTP身份验证,拥有禁用目录列表,使用自定义servlet和代码(可能会引发未处理的异常或未实现所有方法的代码)的准系统Web应用程序上,您需要针对HTTP错误进行设置401分别为403、500和503。 <error-page> <!-- Missing login --> <error-code>401</error-code>
  • Django 1.7 upgrade error: AppRegistryNotReady: Apps aren't loaded yet
    I am trying to upgrade a project from Django 1.6 to 1.7. I get the following error: [Thu Oct 09 14:16:41 2014] [error] [client] mod_wsgi (pid=14523): Exception occurred processing WSGI script '/home/users1/k/kisvadim/domains/mathtasks.org/django.wsgi'. [Thu Oct 09 14:16:41 2014] [error] [client] Traceback (most recent call last): [Thu Oct 09 14:16:41 2014] [error] [client] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__ [Thu Oct 09 14:16:41 2014] [error] [client 95.79
  • Node.js最佳实践异常处理(Node.js Best Practice Exception Handling)
    问题 几天前,我才刚开始尝试使用node.js。 我意识到只要程序中有未处理的异常,Node就会终止。 这与我所见过的普通服务器容器不同,在普通服务器容器中,当发生未处理的异常时,只有工作线程死亡,并且容器仍然能够接收请求。 这引起了一些问题: 是process.on('uncaughtException')防范的唯一有效方法吗? process.on('uncaughtException')也会在异步进程执行期间捕获未处理的异常吗? 是否存在已经构建的模块(例如发送电子邮件或写入文件),在未捕获的异常的情况下可以利用该模块? 我将不胜感激任何向我展示在node.js中处理未捕获的异常的常见最佳实践的指针/文章 回答1 更新:Joyent现在有自己的指南。 以下信息更多是摘要: 安全地“抛出”错误 理想情况下,我们希望尽可能避免未捕获的错误,因此,除了从字面上抛出错误外,我们还可以根据我们的代码体系结构使用以下方法之一安全地“抛出”错误: 对于同步代码,如果发生错误,请返回错误: // Define divider as a syncrhonous function var divideSync = function(x,y) { // if error condition? if ( y === 0 ) { // "throw" the error safely by
  • 删除/重置核心数据中的所有条目?(Delete/Reset all entries in Core Data?)
    问题 您是否知道删除存储在核心数据中的所有条目的任何方法? 我的架构应该保持不变; 我只想将其重置为空白。 编辑 我正在寻找以编程方式执行此操作,以便用户可以基本上单击reset按钮。 回答1 您仍然可以使用NSFileManager:removeItemAtPath ::方法以编程方式删除文件。 NSPersistentStore *store = ...; NSError *error; NSURL *storeURL = store.URL; NSPersistentStoreCoordinator *storeCoordinator = ...; [storeCoordinator removePersistentStore:store error:&error]; [[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error]; 然后,只需添加回永久存储以确保正确创建它即可。 遍历每个实体的编程方式较慢且容易出错。 这样做的用途是,如果您要删除某些实体而不是其他实体。 但是,您仍然需要确保保留参照完整性,否则将无法持久保存所做的更改。 只需删除存储并重新创建它既快速又安全,并且可以肯定地在运行时以编程方式完成。 适用于iOS5 +的更新 随着iOS 5和OS X 10
  • 在发出通知/警告时停止执行脚本(Stop script execution upon notice/warning)
    问题 是否有可能在全局范围内使PHP停止执行通知/警告? 我们运行的开发服务器上有很多站点,但是我们希望迫使我们的开发人员修复这些警告/通知(或至少寻求帮助),而不是忽略并继续前进。 回答1 是的,有可能。 这个问题是关于如何处理PHP中的错误的更普遍的问题。 您应该使用set_error_handlerdocs定义和注册自定义错误处理程序,以自定义PHP错误的处理方式。 恕我直言,最好在任何PHP错误上引发异常,并使用try / catch块来控制程序流,但是在这一点上意见不一。 要实现OP的既定目标,您可以执行以下操作: function errHandle($errNo, $errStr, $errFile, $errLine) { $msg = "$errStr in $errFile on line $errLine"; if ($errNo == E_NOTICE || $errNo == E_WARNING) { throw new ErrorException($msg, $errNo); } else { echo $msg; } } set_error_handler('errHandle'); 每当引发E_NOTICE或E_WARNING时,以上代码都会引发ErrorException ,从而有效地终止脚本输出(如果未捕获到异常)。
  • 如何在CodeIgniter(PHP)中进行错误记录(How to do error logging in CodeIgniter (PHP))
    问题 我想在PHP CodeIgniter中记录错误。 如何启用错误记录? 我有一些疑问: 记录错误的所有步骤是什么? 如何创建错误日志文件? 如何将错误消息推送到日志文件中(无论何时发生错误)? 您如何通过电子邮件将该错误发送到电子邮件地址? 回答1 CodeIgniter内置了一些错误记录功能。 使您的/ application / logs文件夹可写在/application/config/config.php中设置$config['log_threshold'] = 1; 或使用更高的数字,具体取决于您要在日志中获取多少详细信息使用log_message('error', 'Some variable did not contain a value.'); 要发送电子邮件,您需要扩展核心CI_Exceptions类方法log_exceptions() 。 您可以自己执行此操作或使用它。 有关在此处扩展核心的更多信息 参见http://www.codeigniter.com/user_guide/general/errors.html 回答2 要简单地在服务器的错误日志中添加一行,请使用PHP的error_log()函数。 但是,该方法将不会发送电子邮件。 首先,触发错误: trigger_error("Error message here", E_USER_ERROR)
  • “ On Error Resume Next”语句有什么作用?(What does the “On Error Resume Next” statement do?)
    问题 我看了一些VBScript示例,并且基本上在脚本的开头看到了On Error Resume Next语句。 它有什么作用? 回答1 当遇到错误时,它基本上会告诉程序,仅在下一行继续。 回答2 值得注意的是,即使在执行On Error Resume Next时,发生错误时仍会填充Err对象,因此您仍然可以执行C样式的错误处理。 On Error Resume Next DangerousOperationThatCouldCauseErrors If Err Then WScript.StdErr.WriteLine "error " & Err.Number WScript.Quit 1 End If On Error GoTo 0 回答3 发生错误时,将在不中断脚本的情况下继续执行下一行。 回答4 这意味着,当在线发生错误时,它告诉vbscript继续执行而不会中止脚本。 有时, On Error跟随Goto标签来更改执行流程,就像在Sub代码块中这样,现在您知道了为什么以及如何使用GOTO会导致产生意大利面条式代码: Sub MySubRoutine() On Error Goto ErrorHandler REM VB code... REM More VB Code... Exit_MySubRoutine: REM Disable the Error Handler
  • Maven : error in opening zip file when running maven
    [ERROR] error: error reading C:\Users\suresh\.m2\repository\org\jdom\jdom\1.1\jdom-1.1.jar; error in opening zip file [ERROR] error: error reading C:\Users\suresh\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar; error in opening zip file [ERROR] error: error reading C:\Users\suresh\.m2\repository\org\apache\cxf\cxf-rt-bindings-http\2.2.1\cxf-rt-bindings-http-2.2.1.jar; error in opening zip file [ERROR] error: error reading C:\Users\suresh\.m2\repository\org\codehaus\jra\jra\1.0-alpha-4\jra-1.0-alpha-4.jar; error in opening zip file [ERROR] error: error reading C:\Users\suresh\
  • 使用ES6语法和Babel扩展Javascript中的错误(Extending Error in Javascript with ES6 syntax & Babel)
    问题 我正在尝试使用ES6和Babel扩展Error。 它没有解决。 class MyError extends Error { constructor(m) { super(m); } } var error = new Error("ll"); var myerror = new MyError("ll"); console.log(error.message) //shows up correctly console.log(myerror.message) //shows empty string 错误对象永远不会获得正确的消息集。 在Babel REPL中尝试。 现在,我已经看到了一些关于SO的解决方案(例如在这里),但是它们似乎都非常不属于ES6-y。 如何以一种不错的ES6方式做到这一点? (在Babel工作) 回答1 根据KarelBílek的回答,我将对constructor进行一些小的更改: class ExtendableError extends Error { constructor(message) { super(message); this.name = this.constructor.name; if (typeof Error.captureStackTrace === 'function') { Error.captureStackTrace
  • Swift Alamofire:如何获取HTTP响应状态代码(Swift Alamofire: How to get the HTTP response status code)
    问题 我想检索HTTP响应状态代码(例如400、401、403、503等),以获取请求失败(也可以成功获取)。 在此代码中,我正在使用HTTP Basic执行用户身份验证,并希望能够向用户发送消息,当用户键入错误的密码时身份验证失败。 Alamofire.request(.GET, "https://host.com/a/path").authenticate(user: "user", password: "typo") .responseString { (req, res, data, error) in if error != nil { println("STRING Error:: error:\(error)") println(" req:\(req)") println(" res:\(res)") println(" data:\(data)") return } println("SUCCESS for String") } .responseJSON { (req, res, data, error) in if error != nil { println("JSON Error:: error:\(error)") println(" req:\(req)") println(" res:\(res)") println(" data:\(data)")