diff --git a/irr/include/ISceneNode.h b/irr/include/ISceneNode.h index 897cfb350..c80ff4b48 100644 --- a/irr/include/ISceneNode.h +++ b/irr/include/ISceneNode.h @@ -310,7 +310,11 @@ public: \return The material at that index. */ virtual video::SMaterial &getMaterial(u32 num) { - return video::IdentityMaterial; + // We return a default material since a reference can't be null, + // but note that writing to this is a mistake either by a child class + // or the caller, because getMaterialCount() is zero. + // Doing so will helpfully cause a segfault. + return const_cast(video::IdentityMaterial); } //! Get amount of materials used by this scene node. diff --git a/irr/include/SMaterial.h b/irr/include/SMaterial.h index 3bbc6e946..d48328a31 100644 --- a/irr/include/SMaterial.h +++ b/irr/include/SMaterial.h @@ -472,7 +472,7 @@ public: }; //! global const identity Material -IRRLICHT_API extern SMaterial IdentityMaterial; +IRRLICHT_API extern const SMaterial IdentityMaterial; } // end namespace video } // end namespace irr diff --git a/irr/src/Irrlicht.cpp b/irr/src/Irrlicht.cpp index b1818eb55..2e80088ab 100644 --- a/irr/src/Irrlicht.cpp +++ b/irr/src/Irrlicht.cpp @@ -88,7 +88,7 @@ const matrix4 IdentityMatrix(matrix4::EM4CONST_IDENTITY); namespace video { -SMaterial IdentityMaterial; +const SMaterial IdentityMaterial; extern "C" IRRLICHT_API bool IRRCALLCONV isDriverSupported(E_DRIVER_TYPE driver) {