对于C++初学者或粗心者,很容易犯如下图所示错误:
 
 
那么该错误是由什么造成的呢?
 
答案无疑只有一个,即:读取了本该没有的值或者地址。
 
那么如何解决呢?
 
第一件事,检查下你传入的参数是否合法;
第二件事,若malloc了一块内存,必须记得free;

第三件事,你是否赋值了已经溢出的值或地址。

 
举例说明:
 
  1. pOrg = pcPicYuvOrg->getLumaAddr();
  2. for( y = 0; y < height-1; y++ )
  3. {
  4. for( x = 0; x < width-1; x++ )
  5. {
  6. Pel A[4];
  7. //2x2
  8. A[0]=pOrg[x];   A[1]=pOrg[x+1];
  9. A[2]=(pOrg+stride)[x];  A[3]=(pOrg+stride)[x+1];
  10. if( A[0]==255 && A[1]==255 && A[2]==255 && A[3]==255 )
  11. {
  12. pOrg[x] = 255;  pOrg[x+1] = 255;
  13. (pOrg+stride)[x] = 255; (pOrg+stride)[x+1] = 255;
  14. }
  15. else
  16. {
  17. pOrg[x] = 0;    pOrg[x+1] = 0;
  18. (pOrg+stride)[x] = 0;   (pOrg+stride)[x+1] = 0;
  19. }
  20. x += 1;
  21. }
  22. pOrg += 2*stride;
  23. }

此代码就会出现上图所示错误。那么如何解决呢?

 
  1. pOrg = pcPicYuvOrg->getLumaAddr();
  2. for( y = 0; y < height/2; y++ )
  3. {
  4. for( x = 0; x < width-1; x++ )
  5. {
  6. Pel A[4];
  7. //2x2
  8. A[0]=pOrg[x];   A[1]=pOrg[x+1];
  9. A[2]=(pOrg+stride)[x];  A[3]=(pOrg+stride)[x+1];
  10. if( A[0]==255 && A[1]==255 && A[2]==255 && A[3]==255 )
  11. {
  12. pOrg[x] = 255;  pOrg[x+1] = 255;
  13. (pOrg+stride)[x] = 255; (pOrg+stride)[x+1] = 255;
  14. }
  15. else
  16. {
  17. pOrg[x] = 0;    pOrg[x+1] = 0;
  18. (pOrg+stride)[x] = 0;   (pOrg+stride)[x+1] = 0;
  19. }
  20. x += 1;
  21. }
  22. pOrg += 2*stride;
  23. }

很明显,错误的原因在于:赋值了已经溢出的值。

 
若以后遇到类似问题,可以逐步检查上述提出的“三件事情”即可。

Unhandled exception at 0x........ in XXXX.exe: 0xC0000005:错误的更多相关文章

  1. Solve Error: Unhandled exception at 0x00905a4d in xxx.exe: 0xC0000005: Access violation.

    在使用Visual Studio进行项目开发的时候,有时候会遇到下面这个错误: Unhandled exception at 0x00905a4d in xxx.exe: 0xC0000005: Ac ...

  2. NET环境下的未处理异常(unhandled exception)的解决方案

    NET环境下的未处理异常(unhandled exception )的解决方案 .Net 框架提供了非常强大的异常处理机制,同时对一些非托管代码很难控制的系统问题比如指针越界,内存泄漏等提供了很好的解 ...

  3. [转]让程序在崩溃时体面的退出之Unhandled Exception

    原文地址:http://blog.csdn.net/starlee/article/details/6613424 程序是由代码编译出来的,而代码是由人写的.人非圣贤,孰能无过.所以由人写的代码有缺陷 ...

  4. Unhandled Exception: System.BadImageFormatException: Could not load file or assembly (2008R2配置x64website)

    .NET Error Message: Unhandled Exception: System.BadImageFormatException: Could not load file or asse ...

  5. Unhandled Exception:System.DllNotFoundException: Unable to load DLL"**":找不到指定的模块

    在项目中使用C#代码调用C++ DLL时.常常会出现这个问题:在开发者自己的电脑上运行没有问题,但是部署到客户电脑上时会出现下面问题: Unhandled Exception:System.DllNo ...

  6. android Unhandled exception type ParseException提示报错

    Unhandled exception type ParseException 意思指:你有一个方法会抛出异常,但是你没有捕捉. 依提示添加一下即可解决:

  7. JAVA 新手问题: Request 编码编译出错,Unhandled exception type UnsupportedEncodingException

    新手: 编写如下代码 private void Exec(HttpServletRequest Req,HttpServletResponse Response) //throws ServletEx ...

  8. Quartz:ERROR threw an unhandled Exception

    详细的错误信息如下: -- ::] ERROR org.quartz.core.JobRunShell: - Job group1.job1 threw an unhandled Exception: ...

  9. Unhandled Exxception “Unhandled exception type IOException”?

    Unhandled Exxception  “Unhandled exception type IOException”? 在Android studio中,自动遇见这个异常报错,如果eclipse会 ...

随机推荐

  1. The method getJspApplicationContext(ServletContext) is undefined for the type

    type Exception report message Unable to compile class for JSP: description The server encountered an ...

  2. 学习UFT11.5历程(二)

    1. QTP对象TO与RO TO: test object. 本地对象库里的封装对象 RO:run object. 运行封装对象 和TO.RO相关的几个函数有: GetTOProperty(“属性名” ...

  3. iOS - AppRealTest App 真机测试

    前言 1.准备 开发者账号 自从 Xcode7 出来之后,一般的真机测试不需要开发者账号,也就不需要看这篇教程,只有 app 具有 "推送" 等功能的时候,要真机测试就必须要开发者 ...

  4. build.fxbuild打不开 Failed to create the part's controls

    Failed to create the part's controls 以文本形式打开之后,发现编码的地方不是常用编码 将之修改为GBK 然后就可以正常打开了 最后把eclipse中的编码统一设置为 ...

  5. linux建立一个快捷方式,连接到另一个目录

    sudo ln -s 源目录 目标快捷方式比如你要在/etc下面建立一个叫LXBC553的快捷方式,指向/home/LXBC,那就是sudo ln -s /home/LXBC /etc/LXBC553

  6. 可靠UDP

    tcp为我们做了什么事情? 总得来说,tcp做了这几件事: 通过序列号和基于确认的超时重传机制,为上层提供了可靠的字节流服务: 通过滑动窗口.拥塞窗口提供了流量控制: 默认情况下,为了有效利用带宽,t ...

  7. 关于unity碰撞检测器的用法

    今天已经是我第三次忘记了这两种碰撞检测的用法,混淆了.特意整理一下 首先把今天要解决涉及到的东西列出来 碰撞方法: public void OnTriggerEnter(Collider other) ...

  8. js递归方法创建节点

    var jsonData = [{,,"subnetRemark":"状态自带","subnetName":"中心网络" ...

  9. 如何用JS判断推广链接所属的客服

    今天有一个客户提出一个需求:网站有多个在线客服,每个客服都有自己的网站推广链接,当访客通过该客服的推广链接进入网站时,必须指定由该客服接待. 我的实现思路是获取推广链接中特定字符,然后判断字符对应的客 ...

  10. C++ map的遍历

    一般使用迭代器遍历比较方便. map<string,int> m; map<string,int>::iterator it; it = m.begin(); while(it ...