Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
f3c037c1
Commit
f3c037c1
authored
Apr 24, 2014
by
Janis Born
Browse files
add hotfix for memory error in loadTextureDataFromLodepng
parent
bfad7296
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Data/TextureData.hh
View file @
f3c037c1
...
...
@@ -130,7 +130,7 @@ private:
// ========================================================================================================= \/
// ================================================================================================== FIELDS \/
// ========================================================================================================= \/
GLubyte
*
mData
;
GLubyte
*
mData
;
// TODO: make this a std::unique_ptr to allow custom deleters
GLsizei
mWidth
;
GLsizei
mHeight
;
GLsizei
mDepth
;
...
...
src/ACGL/OpenGL/Data/TextureDataLoadStore.cc
View file @
f3c037c1
...
...
@@ -245,14 +245,20 @@ SharedTextureData loadTextureDataFromLodepng(const std::string &_filename, Color
}
// Decode the image
unsigned
char
*
i
mage
;
errorCode
=
lodepng_decode_memory
(
&
i
mage
,
&
width
,
&
height
,
lodepngFile
.
mData
,
lodepngFile
.
mSize
,
colorType
,
bitdepth
);
unsigned
char
*
lodepngI
mage
;
errorCode
=
lodepng_decode_memory
(
&
lodepngI
mage
,
&
width
,
&
height
,
lodepngFile
.
mData
,
lodepngFile
.
mSize
,
colorType
,
bitdepth
);
if
(
errorCode
)
{
std
::
stringstream
errorMsg
;
errorMsg
<<
"LodePNG error while decoding file "
<<
_filename
<<
" - "
<<
errorCode
<<
": "
<<
lodepng_error_text
(
errorCode
);
throw
std
::
runtime_error
(
errorMsg
.
str
());
}
// HOTFIX: TextureData destroys its pointer using delete[], but lodepng uses malloc().
// As a hotfix, copy lodepngImage data to a memory location allocated using new[].
unsigned
int
dataSize
=
width
*
height
*
channels
*
bitdepth
/
8
;
unsigned
char
*
image
=
new
unsigned
char
[
dataSize
];
memcpy
(
image
,
lodepngImage
,
dataSize
);
free
(
lodepngImage
);
// LodePNG decodes 16 bit PNGs in big endian format ==> Convert
#ifndef ACGL_BIG_ENDIAN
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment