diff options
author | kasper93 <kasper93@gmail.com> | 2014-09-07 00:22:58 +0400 |
---|---|---|
committer | kasper93 <kasper93@gmail.com> | 2014-09-20 00:19:24 +0400 |
commit | 2a0d0c2d49032cad240147db0cb1f252358bc7b6 (patch) | |
tree | 8f333bfe7af0560b4334349f4f287aa4c7908255 /src | |
parent | ab173b5cae503a03625ae65173e6adfbfa8bd17b (diff) |
Properly catch a bad allocation exception.
On MFC projects `CMemoryException` is thrown instead of the
STL's `std::bad_alloc` exception.
Diffstat (limited to 'src')
-rw-r--r-- | src/SubPic/DX7SubPic.cpp | 3 | ||||
-rw-r--r-- | src/SubPic/DX9SubPic.cpp | 3 | ||||
-rw-r--r-- | src/SubPic/MemSubPic.cpp | 6 | ||||
-rw-r--r-- | src/Subtitles/RTS.cpp | 21 | ||||
-rw-r--r-- | src/Subtitles/VobSubFile.cpp | 3 | ||||
-rw-r--r-- | src/Subtitles/VobSubImage.cpp | 12 |
6 files changed, 32 insertions, 16 deletions
diff --git a/src/SubPic/DX7SubPic.cpp b/src/SubPic/DX7SubPic.cpp index e044ade19..e67e744e9 100644 --- a/src/SubPic/DX7SubPic.cpp +++ b/src/SubPic/DX7SubPic.cpp @@ -293,7 +293,8 @@ bool CDX7SubPicAllocator::Alloc(bool fStatic, ISubPic** ppSubPic) try {
*ppSubPic = DEBUG_NEW CDX7SubPic(m_pD3DDev, pSurface);
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return false;
}
diff --git a/src/SubPic/DX9SubPic.cpp b/src/SubPic/DX9SubPic.cpp index c6f18d774..3cbeac986 100644 --- a/src/SubPic/DX9SubPic.cpp +++ b/src/SubPic/DX9SubPic.cpp @@ -445,7 +445,8 @@ bool CDX9SubPicAllocator::Alloc(bool fStatic, ISubPic** ppSubPic) try {
*ppSubPic = DEBUG_NEW CDX9SubPic(pSurface, fStatic ? nullptr : this, m_bExternalRenderer);
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return false;
}
diff --git a/src/SubPic/MemSubPic.cpp b/src/SubPic/MemSubPic.cpp index 19498de01..1505f4cb0 100644 --- a/src/SubPic/MemSubPic.cpp +++ b/src/SubPic/MemSubPic.cpp @@ -602,13 +602,15 @@ bool CMemSubPicAllocator::Alloc(bool fStatic, ISubPic** ppSubPic) spd.type = m_type;
try {
spd.bits = DEBUG_NEW BYTE[spd.pitch * spd.h];
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return false;
}
try {
*ppSubPic = DEBUG_NEW CMemSubPic(spd);
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
delete [] spd.bits;
return false;
}
diff --git a/src/Subtitles/RTS.cpp b/src/Subtitles/RTS.cpp index 84ad1ba93..ec158b73d 100644 --- a/src/Subtitles/RTS.cpp +++ b/src/Subtitles/RTS.cpp @@ -788,7 +788,8 @@ CClipper::CClipper(CStringW str, const CSize& size, double scalex, double scaley try {
m_pAlphaMask = DEBUG_NEW BYTE[alphaMaskSize];
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return;
}
@@ -1207,7 +1208,8 @@ CLine* CSubtitle::GetNextLine(POSITION& pos, int maxwidth) CLine* ret;
try {
ret = DEBUG_NEW CLine();
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return nullptr;
}
@@ -1302,7 +1304,8 @@ void CSubtitle::CreateClippers(CSize size) str.Format(L"m %d %d l %d %d %d %d %d %d", 0, 0, w, 0, w, h, 0, h);
try {
m_pClipper = DEBUG_NEW CClipper(str, size, 1, 1, false, CPoint(0, 0), m_renderingCaches);
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return;
}
}
@@ -1341,7 +1344,8 @@ void CSubtitle::CreateClippers(CSize size) try {
m_pClipper = DEBUG_NEW CClipper(str, size, 1, 1, false, CPoint(0, 0),
m_renderingCaches);
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return;
}
}
@@ -1710,7 +1714,8 @@ void CRenderedTextSubtitle::ParseEffect(CSubtitle* sub, CString str) Effect* e;
try {
e = DEBUG_NEW Effect;
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return;
}
@@ -1737,7 +1742,8 @@ void CRenderedTextSubtitle::ParseEffect(CSubtitle* sub, CString str) Effect* e;
try {
e = DEBUG_NEW Effect;
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return;
}
@@ -2625,7 +2631,8 @@ CSubtitle* CRenderedTextSubtitle::GetSubtitle(int entry) try {
sub = DEBUG_NEW CSubtitle(m_renderingCaches);
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
+ e->Delete();
return nullptr;
}
diff --git a/src/Subtitles/VobSubFile.cpp b/src/Subtitles/VobSubFile.cpp index 5cfbb7643..5ec54897c 100644 --- a/src/Subtitles/VobSubFile.cpp +++ b/src/Subtitles/VobSubFile.cpp @@ -1158,8 +1158,9 @@ BYTE* CVobSubFile::GetPacket(size_t idx, size_t& packetSize, size_t& dataSize, s try {
ret = DEBUG_NEW BYTE[packetSize];
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
ASSERT(FALSE);
+ e->Delete();
break;
}
diff --git a/src/Subtitles/VobSubImage.cpp b/src/Subtitles/VobSubImage.cpp index 427fddcbc..e0582b203 100644 --- a/src/Subtitles/VobSubImage.cpp +++ b/src/Subtitles/VobSubImage.cpp @@ -64,15 +64,17 @@ bool CVobSubImage::Alloc(int w, int h) try {
lpTemp1 = DEBUG_NEW RGBQUAD[w * h];
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
ASSERT(FALSE);
+ e->Delete();
return false;
}
try {
lpTemp2 = DEBUG_NEW RGBQUAD[(w + 2) * (h + 2)];
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
ASSERT(FALSE);
+ e->Delete();
delete [] lpTemp1;
lpTemp1 = nullptr;
return false;
@@ -397,8 +399,9 @@ CAutoPtrList<COutline>* CVobSubImage::GetOutlineList(CPoint& topleft) CAutoPtrList<COutline>* ol;
try {
ol = DEBUG_NEW CAutoPtrList<COutline>();
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
ASSERT(FALSE);
+ e->Delete();
return nullptr;
}
@@ -444,8 +447,9 @@ CAutoPtrList<COutline>* CVobSubImage::GetOutlineList(CPoint& topleft) CAutoPtr<COutline> o;
try {
o.Attach(DEBUG_NEW COutline);
- } catch (std::bad_alloc) {
+ } catch (CMemoryException* e) {
ASSERT(FALSE);
+ e->Delete();
break;
}
|