Commit 5fe87463 authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

more debug info to hack large file loading and memory allocation

parent 0e0aa9ea
......@@ -167,7 +167,7 @@ void DImgLoader::loadingFailed()
m_image->m_priv->height = 0;
}
int DImgLoader::checkAllocation(qint64 fullSize)
qint64 DImgLoader::checkAllocation(qint64 fullSize)
{
if (fullSize > std::numeric_limits<int>::max())
{
......@@ -175,22 +175,29 @@ int DImgLoader::checkAllocation(qint64 fullSize)
return 0;
}
int size = (int)fullSize;
// Do extra check if allocating serious amounts of memory.
// At the time of writing (2011), I consider 100 MB as "serious".
if (size > 100 * 1024 * 1024)
if (fullSize > (qint64)(100 * 1024 * 1024))
{
KMemoryInfo memory = KMemoryInfo::currentInfo();
if (size > memory.bytes(KMemoryInfo::AvailableMemory) && memory.isValid())
if (!memory.isValid())
{
kError() << "Error to get physical memory information";
return 0;
}
qint64 available = memory.bytes(KMemoryInfo::AvailableMemory);
if (fullSize > available)
{
kError() << "Not enough memory to allocate buffer of size" << size;
kError() << "Not enough memory to allocate buffer of size " << fullSize;
kError() << "Available memory size is " << available;
return 0;
}
}
return size;
return fullSize;
}
bool DImgLoader::readMetadata(const QString& filePath, DImg::FORMAT /*ff*/)
......
......@@ -90,7 +90,7 @@ public:
static unsigned short* new_short_failureTolerant(size_t unsecureSize);
static unsigned short* new_short_failureTolerant(quint64 w, quint64 h, uint typesPerPixel);
static int checkAllocation(qint64 fullSize);
static qint64 checkAllocation(qint64 fullSize);
template <typename Type> static Type* new_failureTolerant(size_t unsecureSize);
template <typename Type> static Type* new_failureTolerant(quint64 w, quint64 h, uint typesPerPixel);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment