- 论坛徽章:
- 0
|
在这里内存分配失败,可是在其他的函数分配比这里还大的空间也没问题
unsigned char* volumeData = new unsigned char[uncompressedSize];
·————————————————错误提示
uncompressedSize = 315698688
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
·————————————————関数
int ProjectController: penProject(RzApplicationContext *app,
QString projfolder) {
QDir pdir(projfolder);
QString strPFile = pdir.absoluteFilePath("RzContour.rc" ;
QString strVFile = pdir.absoluteFilePath("RzVolume.rzv" ;
QFile filePrj(strPFile);
QFile fileVol(strVFile);
//Error, Volume data is zero
if(fileVol.size()==0)
return -1;
//Read VolumeData
fileVol.open(QIODevice::ReadOnly);
QDataStream volstream(&fileVol);
QByteArray volCmprsdByteArray;
int nx, ny, nz, bbp;
int voltype;
volstream >> nx;
volstream >> ny;
volstream >> nz;
volstream >> bbp;
volstream >> voltype;
volstream >> volCmprsdByteArray;
QByteArray volUncmprsdByeArray = qUncompress(volCmprsdByteArray);
//Create New Project
ProjectController::newProject(app);
RzProjectContext *prjCtx = app->getProjectContext();
RzContourContext *contourCtx =
(RzContourContext*) prjCtx->getPluginContext("RzContourContext" ;
int uncompressedSize = volUncmprsdByeArray.size();
qDebug("uncompressedSize = %i",uncompressedSize);
unsigned char* volumeData = new unsigned char[uncompressedSize];
qDebug("After new uncompressedSize = %i",uncompressedSize);
//Create New Volume Data
RzVolume *rzvol = new RzVolume();
rzvol->setXSize(nx);
rzvol->setYSize(ny);
rzvol->setZSize(nz);
rzvol->setBytesPerPixel(bbp);
rzvol->setVolumeType(voltype);
unsigned char* source = (unsigned char*) volUncmprsdByeArray.data();
//memcpy()
memcpy(volumeData, source, uncompressedSize);
rzvol->setData(volumeData);
rzvol->setSavedChanges(true);
prjCtx->setVolumeData(rzvol);
//Now load contour data using XML parser
ProjectXMLHandler handler(contourCtx, rzvol);
QXmlSimpleReader xmlReader;
xmlReader.setContentHandler(&handler);
xmlReader.setErrorHandler(&handler);
QXmlInputSource inputSource(&filePrj);
xmlReader.parse(inputSource);
if(!handler.isValidRinzoFormat())
return -1;
prjCtx->setProjectFolder(projfolder);
//qDebug()
return 0;
} |
|