对于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. treap 模版

    struct Treap { struct node { node *son[]; int key,siz,wei,cnt; node(int _key,node *f) { son[]=son[]= ...

  2. Git 使用教程

    Git 使用教程 更详细请参考:廖雪峰的官方网站 - Git教程 1. 安装Git客户端软件 Git for Windows http://msysgit.github.io/ 2. 创建版本库 两点 ...

  3. [bzoj2743][HEOI2012]采花(树状数组+离线)

    2743: [HEOI2012]采花 Time Limit: 15 Sec  Memory Limit: 128 MBSubmit: 1832  Solved: 954[Submit][Status] ...

  4. SQLiteDatabase 基本操作

    一.SQLiteOpenHelper类 android 提供类SQLiteOpenHelper帮助用户简化对SQLite数据库的操作.该类是一个抽象类,必须用户自己实现并重写oncreate()和on ...

  5. windows server 2003(64位)上利用iis6部署32位应用

    如果直接部署,会出现如下问题: 试图加载格式不正确的程序. (Exception from HRESULT: 0x8007000B) 解决办法 1.命令行键入: cscript.exe %SYSTEM ...

  6. 重温Javascript第一章

    一.script标签 script标签有6个属性,其中一个废弃,五个可选. 按照传统的写法,<script>的标签都是放在<head>元素中,但是在<head>中包 ...

  7. (46) odoo核心文档分享

    *前言: 要掌握一个系统,还得有扎实的基础,最好的方法,阅读核心文档 然后去实践. *核心文档列表如下: odoo8官方参考.pdf                      链接: http://p ...

  8. 基础算法之插入排序Insertion Sort

    原理 通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入.通常采用in-place排序(即只需用到O(1)的额外空间的排序),因而在从后向前扫描过程中,需要反复把已排序元 ...

  9. How threads differ from processes

    How threads differ from processes Threads differ from traditional multitasking operating system proc ...

  10. css学习归纳总结(二) 转

    原文地址:css学习归纳总结(二) 标签与元素 <p>标签和p元素有什么区别呢?大多数时候他们表示的是同一样东西,但仍有细微的区别.<p>.<div>等指的是HTM ...