对于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. MySQL 5.6 双机热备windows7

    MySQL 5.6 双机热备 目录: 1.说明 2.数据手工同步 3.修改主数据库配置文件 4.修改从数据库配置文件 5.主数据库添加备份用户 6.从数据库设置为Slave 7.验证 1.说明 1)数 ...

  2. for循环j = j++ 和 j = ++j

    package com.test.forname; public class TestForName { public static void main(String[] args) throws E ...

  3. C# redis使用

    1.下载安装Redis常用组件 下载地址https://github.com/dmajkic/redis/downloads 把文件内容拷贝到需要安装的目录下,如:E:\redis-2.8.172.启 ...

  4. 【树莓派】树莓派使用4G模块上网

    想了解一下树莓派通过4G网络模块通信如何实现,看到这篇文章(http://www.lxway.com/95811506.htm),准备接下来有机会实践一下,先留存学习: 一.4G Luci配置 1. ...

  5. application、viewstate、纯HTML提交方式

    Application - 全局公共变量组 存放位置:服务端 所有的访问用户都是访问的同一个变量 声明周期:永久 用法同session类似 viewstate-病例 因为http的无状态性,需要记录上 ...

  6. input type="number"

    情景: 移动端 input控件,调数字键盘,在输入小数点时光标会自动跳到小数点前面.安卓6.0.1的版本会这样. question: 1.调原生数字键盘的方法,必须用 type="numbe ...

  7. checkbox属性checked="checked"已有,但却不显示打勾的解决办法

    2014-02-05 BIWEB开发技巧 9919 在做权限管理的时候,做了一个功能,就是当勾选栏目,把所有的权限全勾上.刚开始使用了如下代码: function check(id,check) { ...

  8. Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 更新关系数据

    Updating related data¶ 7 of 7 people found this helpful The Contoso University sample web applicatio ...

  9. swift_属性观察者

    //: Playground - noun: a place where people can play import Cocoa var str = "Hello, playground& ...

  10. RedHat下Bugzilla的安装和配置

    Bugzilla 是一个开源的缺陷跟踪系统(Bug-Tracking System). OS:RedHat Linux 软件类型:开源 架构:B/S server端模块开发语言:perl(c/c++) ...