对于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. InfoPackage的更新模式

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. Mac上配置Privoxy

    此文档适用于走Shadowsocks代理,想利用Privoxy将主机作为代理服务器的用户. 0.安装完Privoxy后,打开终端命令. 1.打开Privoxy的配置文件config: cd /usr/ ...

  3. Linux中设置服务自启动的三种方式

    有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s                       在/etc/rc.d/rc*.d目录中建立/e ...

  4. JQ入门学习实战演练

    选择器是JQuery一大特色,所有的DOM操作.事件操作.Ajax操作都离不开选择器.熟练掌握JQuery的选择器,可以节省很多代码,很大程序上简化我们的脚本编程工作. JQuery的选择器很类似于样 ...

  5. PHP简单文件上传

    一个简单的PHP上传文件的例子: upload.html <html> <body> <form action="upload.php" method ...

  6. 使用JS实现轮播图的效果

    其中的一些css样式代码就省略了,下面只把结构层html.行为层js的代码展示出来 ,看代码说事. 一.简单的轮播图 <div class="box" id="bo ...

  7. 初识App安全性测试

    目前手机App测试还是以发现bug为主,主要测试流程就是服务器接口测试,客户端功能性覆盖,以及自动化配合的性能,适配,压测等,对于App安全性测试貌似没有系统全面统一的标准和流程,其实安全性bug也可 ...

  8. JSONObject,JSONArray,Map,String之间转换

    http://blog.csdn.net/superit401/article/details/51727739 1.String转JSONObject String jsonMessage = &q ...

  9. 在重新生成解决方案时,出现的错误:无法将文件“obj\x86\Debug\*.exe”复制到“obj\Debug\*.exe”。文件正由另一进程使用,因此该进程无法访问此文件

    此例是VS2010的CS项目. 在重新生成解决方案时,出现的错误. 解决步骤:先关闭解决方案,再在项目文件下的bin\Debug\*.exe删除这类之前生成得.exe文件,再在VS2010下重新生成.

  10. ComboboxColumn取值——Winform中DataGridView中某一列使用下拉框

    ComboboxColumn的用法网上很多,绑定数据源都很简单,这里我遇到的是.不绑定数据源,即所有comobox的绑定都是固定的几个数据: 可以看到没有绑定任何数据源, ,在后台cs中取到下拉框的值 ...