From 4cd14d5c08b426d4929b24ffce75c39b68910df5 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 9 Apr 2013 23:39:20 -0300 Subject: [PATCH] Made the getSize() and getData() methods for CompressedData consistent with each other. Note that CompressedData's data may not all be contiguous in memory, so getData(miplevel) and getSize(miplevel) should always be used instead. --HG-- branch : image-CompressedData --- src/modules/image/CompressedData.cpp | 21 +++++++++++++-------- src/modules/image/CompressedData.h | 4 +++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/modules/image/CompressedData.cpp b/src/modules/image/CompressedData.cpp index b3aaa6eb7..132e9f784 100644 --- a/src/modules/image/CompressedData.cpp +++ b/src/modules/image/CompressedData.cpp @@ -36,18 +36,23 @@ CompressedData::~CompressedData() int CompressedData::getSize() const { - size_t totalsize = sizeof(SubImage) * dataImages.size(); - - for (size_t i = 0; i < dataImages.size(); i++) - totalsize += dataImages[i].size; - - return totalsize; + // Adding up the total size for all mipmap levels would make more sense, but + // it's probably better for getSize() to match getData() so no bad memory + // accesses happen... + if (dataImages.size() > 0) + return dataImages[0].size; + else + return 0; } void *CompressedData::getData() const { - // ? - return (void *) &dataImages[0].data[0]; + // Data for different mipmap levels is not stored contiguously in memory, so + // getData() won't work properly for CompressedData. + if (dataImages.size() > 0) + return (void *) &(dataImages[0].data[0]); + else + return 0; } int CompressedData::getNumMipmaps() const diff --git a/src/modules/image/CompressedData.h b/src/modules/image/CompressedData.h index 9740f30e9..6ffbe6f0c 100644 --- a/src/modules/image/CompressedData.h +++ b/src/modules/image/CompressedData.h @@ -70,7 +70,9 @@ public: CompressedData(); virtual ~CompressedData(); - // Implements Data. + // Implements Data. Note that data for different mipmap levels is not always + // stored contiguously in memory, so getData() and getSize() don't make + // much sense. Use getData(miplevel) and getSize(mipleveL) instead. virtual void *getData() const; virtual int getSize() const;