一个关于C++野指针报错的问题

wwwcarl 2014-01-06 10:39:53
愚生用C++做个测试工具,程序运行之后遇到这么一个报错,如果改成release编译会直接说程序有个错误,我该如何解决,.cpp的代码如下(没完全写完),愚生过于愚笨,忘大神们指教~

// MFCApplication1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "MFCApplication1.h"
#include "MFCApplication1Dlg.h"
#include "afxdialogex.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CMFCApplication1Dlg dialog



CMFCApplication1Dlg::CMFCApplication1Dlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CMFCApplication1Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
nPort =NULL;
nPause = PLAY;
}

void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
// DDX_Control(pDX, IDC_PLAY, m_play);
DDX_Control(pDX, IDC_PLAY, m_play);
//DDX_Control(pDX, IDC_IMAGE, m_image);
// DDX_Control(pDX, IDC_RADIO1, m_Radio_Hk);
}

BEGIN_MESSAGE_MAP(CMFCApplication1Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, &CMFCApplication1Dlg::OnBnClickedButton1)
ON_BN_CLICKED(IDOK, &CMFCApplication1Dlg::OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, &CMFCApplication1Dlg::OnBnClickedCancel)


END_MESSAGE_MAP()


// CMFCApplication1Dlg message handlers

BOOL CMFCApplication1Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

void CMFCApplication1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CMFCApplication1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMFCApplication1Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}



void CMFCApplication1Dlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CString str;
DWORD version = HK::PlayM4_GetSdkVersion();
//str.Format(_T("%lu"),version);
char path[1024];
memset(path,0,1024);
sprintf_s(path,"%s","20131226_20131226155939_20131226160037_155724.mp4");
nPort = ( LONG* )malloc( sizeof( long ));
CWnd *pWnd = GetDlgItem(IDC_PLAY);
HWND hwnd = pWnd->GetSafeHwnd();
selectFlag = GetCheckedRadioButton(IDC_RADIO_HK,IDC_RADIO_OT);
if(IDC_RADIO_HK == selectFlag )
{

if(HK::PlayM4_GetPort(nPort))
{
int l = int(*nPort);
str.Format(_T("%d"),l);
//AfxMessageBox(str);
}else{
AfxMessageBox(_T("err"));
}

long count = long(HK::PlayM4_GetFileTotalFrames(*nPort));
AfxMessageBox(_T("%l"),count);
if(!HK::PlayM4_OpenFile(*nPort,path))
{
AfxMessageBox(_T("cun"));
}else{
AfxMessageBox(CString(path));
}
HK::PlayM4_SetFileRefCallBack(*nPort,NULL,1);
if(!HK::PlayM4_SetStreamOpenMode(*nPort,STREAME_FILE))
{
AfxMessageBox(_T("Stream Err"));
}
//PlayM4_OpenFile()
HK::PlayM4_SetDisplayBuf(*nPort,MAX_DISPLAY_WND);
if(*nPort > 0 )
{
// CWnd *pWnd = GetDlgItem(IDC_IMAGE);
}


if(!HK::PlayM4_Play(*nPort,hwnd))
{

AfxMessageBox(_T("paly err"));

}else{
nPause = PLAY;
//Sleep(5000);
int k = int(HK::PlayM4_GetPlayedTimeEx(*nPort));
long l = long(HK::PlayM4_GetCurrentFrameNum(*nPort));
str.Format(_T("%l"),l);
AfxMessageBox(str);
}
}else if(IDC_RADIO_DH == selectFlag)
{
DH::PLAY_GetFreePort(nPort);
if(!DH::PLAY_OpenFile(*nPort,path))
{

}else{
if(!DH::PLAY_Play(*nPort,hwnd)){

}else{

}
}


}



//(PlayM4_ReversePlay)
//PlayM4_Stop();
//PlayM4_CloseFile();
//PlayM4_FreePort();
//AfxMessageBox(str);



}


void CMFCApplication1Dlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
//CDialogEx::OnOK();
if(IDC_RADIO_HK == selectFlag){

while(!HK::PlayM4_Stop(*nPort))
{
Sleep(2000);
}

HK::PlayM4_CloseFile(*nPort);
HK::PlayM4_FreePort(*nPort);

}else if(IDC_RADIO_DH == selectFlag){
DH::PLAY_Stop(*nPort);
DH::PLAY_CloseFile(*nPort);
DH::PLAY_ReleasePort(*nPort);
}
nPause = STOP;
}


void CMFCApplication1Dlg::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
//CDialogEx::OnCancel();
if(IDC_RADIO_HK == selectFlag){

if(nPause == PLAY)
{
HK::PlayM4_Pause(*nPort,FALSE);
nPause = PAUSE;
}else if(nPause == PAUSE)
{
HK::PlayM4_Pause(*nPort,TRUE);
nPause = PLAY;
}else if(nPause == STOP)
{
AfxMessageBox(_T("没有视频流"));
}
}else if(IDC_RADIO_DH == selectFlag){
if(nPause == PLAY)
{
DH::PLAY_Pause(*nPort,FALSE);
nPause = PAUSE;

}else if(nPause == PAUSE)
{
DH::PLAY_Pause(*nPort,TRUE);
nPause = PLAY;
}else if(nPause == STOP)
{
AfxMessageBox(_T("没有视频流"));
}
}

}



...全文
281 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SKATE11 2014-01-06
  • 打赏
  • 举报
回复
release下面 数组越界都会导致程序崩溃
zhuobattle 2014-01-06
  • 打赏
  • 举报
回复
Debug版本 F5调试运行,遇错后点击重试,然后看堆栈,立马可以找到问题。
merlinfang 2014-01-06
  • 打赏
  • 举报
回复
这个断言,你看下堆栈的你写的代码里面就知道了, 看起来是哪个Format之类写错了。
wwwcarl 2014-01-06
  • 打赏
  • 举报
回复
引用 1 楼 merlinfang 的回复:
这个断言,你看下堆栈的你写的代码里面就知道了, 看起来是哪个Format之类写错了。
是format的错误,谢谢哈~问题解决了~ 还有一个问题哈~我这是句柄播放的视频~如果我想通过解码回调来播放视频应该如何操作呢,这是解码回调函数,怎么获取解码后的参数
6.60.解码回调PlayM4_SetDecCallBack
函数: BOOL PlayM4_SetDecCallBack(LONG nPort,void (CALLBACK* DecCBFun)(long
nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long
nReserved2))
参数: LONG nPort
void (CALLBACK* DecCBFun)
DecCBFun 回调函数参数说明
long nPort
char * pBuf
long nSize
FRAME_INFO *pFrameInfo
long nReserved1
long nReserved2
播放通道号
解码回调函数指针,若不需要调用回调函数则
置为NULL,否则不能为NULL
播放器通道号
解码后的音视频数据指针
解码后的音视频数据pBuf 的长度
图像和声音信息结构体指针
保留参数
保留参数
播放库. SDK 编程指南
杭州海康威视数字技术股份有限公司| 版权所有(C)
41
FRAME_INFO 结构说明
typedef struct{
long nWidth;
long nHeight;
long nStamp;
long nType
long nFrameRate;
DWORD dwFrameNum;
}FRAME_INFO;
宏定义说明
T_AUDIO16
T_RGB32
T_UYVY
T_YV12
画面宽,单位像素。如果是音频数据则为音频
声道数;
画面高。如果是音频数据则为样位率;
时标信息,单位毫秒
数据类型,T_AUDIO16,T_RGB32, T_YV12
编码时产生的图像帧率,如果是音频数据则为
采样率
帧号
音频数据;采样率16khz,单声道,每个采样点
16 位表示。
视频数据。每个像素4 个字节,排列方式与位
图相似,“B-G-R-0 …”,第一个像素位于图像
左下角。
视频数据,uyvy 格式。
“U0-Y0-V0-Y1-U2-Y2-V2-Y3….”,第一个像素
位于图像左上角。
视频数据,yv12 格式。排列顺序“Y0-Y1-……”,
“V0-V1….”,“U0-U1-…..”。
关于图像格式详细信息,用户可以查阅相关资
料。
返回值: 成功返回TURE;失败返回FALSE
说明: 设置回调函数,替换播放器中的显示部分,由用户自己控制显示,该函数在
PlayM4_Play 之前调用,在PlayM4_Stop 时自动失效,下次调用PlayM4_Play 之前
需要重新设置。
注意: 解码部分不控制速度,只要用户从回调函数中返回,解码器就会解码下一部分数
据。这个功能的使用需要用户对视频显示和声音播放有足够的了解,否则请慎重
使用,有关知识请参阅directx 开发包。
当前解码的视频数据格式为YV12,音频解码格式为PCM。
调用此回调函数后,则视频图像无显示。

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧