From 69949b991ad308e374a1c395f9f957a4de65eac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 Sep 2015 01:07:32 +0200 Subject: [PATCH] Fix memory corruption on MSVC. I can't believe that you can just forget to include some file and it will SILENTLY PASS and then crashes horribly at runtime because each translation unit thought that given member function pointer had completely different size. THIS IS NOT ACCEPTABLE. --- src/Magnum/Implementation/FramebufferState.h | 7 +++++++ src/Magnum/Implementation/QueryState.h | 7 +++++++ src/Magnum/Implementation/ShaderProgramState.h | 7 +++++++ src/Magnum/Implementation/TextureState.h | 7 +++++++ src/Magnum/Implementation/TransformFeedbackState.h | 12 +++++++++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Magnum/Implementation/FramebufferState.h b/src/Magnum/Implementation/FramebufferState.h index 360bfaaef..d3f01ad40 100644 --- a/src/Magnum/Implementation/FramebufferState.h +++ b/src/Magnum/Implementation/FramebufferState.h @@ -30,6 +30,13 @@ #include "Magnum/Framebuffer.h" +#ifdef _MSC_VER +/* Otherwise the member function pointers will have different size based on + whether the header was included or not. CAUSES SERIOUS MEMORY CORRUPTION AND + IS NOT CAUGHT BY ANY WARNING WHATSOEVER! AARGH! */ +#include "Magnum/Renderbuffer.h" +#endif + namespace Magnum { namespace Implementation { struct FramebufferState { diff --git a/src/Magnum/Implementation/QueryState.h b/src/Magnum/Implementation/QueryState.h index 363ec5b8f..771135a3e 100644 --- a/src/Magnum/Implementation/QueryState.h +++ b/src/Magnum/Implementation/QueryState.h @@ -27,7 +27,14 @@ #include +#include "Magnum/Magnum.h" + +#ifdef _MSC_VER +/* Otherwise the member function pointers will have different size based on + whether the header was included or not. CAUSES SERIOUS MEMORY CORRUPTION AND + IS NOT CAUGHT BY ANY WARNING WHATSOEVER! AARGH! */ #include "Magnum/AbstractQuery.h" +#endif #if defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2) #error this header is not available in WebGL 1.0 build diff --git a/src/Magnum/Implementation/ShaderProgramState.h b/src/Magnum/Implementation/ShaderProgramState.h index d972729d4..9c0ceba56 100644 --- a/src/Magnum/Implementation/ShaderProgramState.h +++ b/src/Magnum/Implementation/ShaderProgramState.h @@ -31,6 +31,13 @@ #include "Magnum/Magnum.h" #include "Magnum/OpenGL.h" +#ifdef _MSC_VER +/* Otherwise the member function pointers will have different size based on + whether the header was included or not. CAUSES SERIOUS MEMORY CORRUPTION AND + IS NOT CAUGHT BY ANY WARNING WHATSOEVER! AARGH! */ +#include "Magnum/AbstractShaderProgram.h" +#endif + namespace Magnum { namespace Implementation { struct ShaderProgramState { diff --git a/src/Magnum/Implementation/TextureState.h b/src/Magnum/Implementation/TextureState.h index 6d2eeabf2..f6c31be43 100644 --- a/src/Magnum/Implementation/TextureState.h +++ b/src/Magnum/Implementation/TextureState.h @@ -30,6 +30,13 @@ #include "Magnum/CubeMapTexture.h" +#ifdef _MSC_VER +/* Otherwise the member function pointers will have different size based on + whether the header was included or not. CAUSES SERIOUS MEMORY CORRUPTION AND + IS NOT CAUGHT BY ANY WARNING WHATSOEVER! AARGH! */ +#include "Magnum/BufferTexture.h" +#endif + namespace Magnum { namespace Implementation { struct TextureState { diff --git a/src/Magnum/Implementation/TransformFeedbackState.h b/src/Magnum/Implementation/TransformFeedbackState.h index ebfb431c6..97830a1bf 100644 --- a/src/Magnum/Implementation/TransformFeedbackState.h +++ b/src/Magnum/Implementation/TransformFeedbackState.h @@ -25,7 +25,17 @@ DEALINGS IN THE SOFTWARE. */ -#include "Magnum/Context.h" +#include + +#include "Magnum/Magnum.h" +#include "Magnum/OpenGL.h" + +#ifdef _MSC_VER +/* Otherwise the member function pointers will have different size based on + whether the header was included or not. CAUSES SERIOUS MEMORY CORRUPTION AND + IS NOT CAUGHT BY ANY WARNING WHATSOEVER! AARGH! */ +#include "Magnum/TransformFeedback.h" +#endif #ifdef MAGNUM_TARGET_GLES2 #error this header is not available in OpenGL ES 2.0 build