From cf34707e273b299c816abedf75d561eef4b609ba Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Wed, 6 Jun 2018 17:57:15 -0230 Subject: [PATCH] Use smart pointer to store static scanline data in FBSurface. - in working on the OpenBSD crashing issue, I noticed that we can use a unique_ptr here --- src/common/FBSurfaceSDL2.cxx | 15 ++++----------- src/common/FBSurfaceSDL2.hxx | 4 ++-- src/common/FrameBufferSDL2.cxx | 4 ++-- src/common/FrameBufferSDL2.hxx | 4 ++-- src/emucore/FrameBuffer.hxx | 4 ++-- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/common/FBSurfaceSDL2.cxx b/src/common/FBSurfaceSDL2.cxx index 86a487f8c..0178af4d6 100644 --- a/src/common/FBSurfaceSDL2.cxx +++ b/src/common/FBSurfaceSDL2.cxx @@ -28,8 +28,7 @@ FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer, myTexAccess(SDL_TEXTUREACCESS_STREAMING), myInterpolate(false), myBlendEnabled(false), - myBlendAlpha(255), - myStaticData(nullptr) + myBlendAlpha(255) { createSurface(width, height, data); } @@ -41,12 +40,6 @@ FBSurfaceSDL2::~FBSurfaceSDL2() SDL_FreeSurface(mySurface); free(); - - if(myStaticData) - { - delete[] myStaticData; - myStaticData = nullptr; - } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -173,7 +166,7 @@ void FBSurfaceSDL2::reload() // If the data is static, we only upload it once if(myTexAccess == SDL_TEXTUREACCESS_STATIC) - SDL_UpdateTexture(myTexture, nullptr, myStaticData, myStaticPitch); + SDL_UpdateTexture(myTexture, nullptr, myStaticData.get(), myStaticPitch); // Blending enabled? if(myBlendEnabled) @@ -225,8 +218,8 @@ void FBSurfaceSDL2::createSurface(uInt32 width, uInt32 height, { myTexAccess = SDL_TEXTUREACCESS_STATIC; myStaticPitch = mySurface->w * 4; // we need pitch in 'bytes' - myStaticData = new uInt32[mySurface->w * mySurface->h]; - SDL_memcpy(myStaticData, data, mySurface->w * mySurface->h * 4); + myStaticData = make_unique(mySurface->w * mySurface->h); + SDL_memcpy(myStaticData.get(), data, mySurface->w * mySurface->h * 4); } applyAttributes(false); diff --git a/src/common/FBSurfaceSDL2.hxx b/src/common/FBSurfaceSDL2.hxx index 3bf8ce856..e36dccf99 100644 --- a/src/common/FBSurfaceSDL2.hxx +++ b/src/common/FBSurfaceSDL2.hxx @@ -88,8 +88,8 @@ class FBSurfaceSDL2 : public FBSurface bool myBlendEnabled; // Blending is enabled uInt8 myBlendAlpha; // Alpha to use in blending mode - uInt32* myStaticData; // The data to use when the buffer contents are static - uInt32 myStaticPitch; // The number of bytes in a row of static data + unique_ptr myStaticData; // The data to use when the buffer contents are static + uInt32 myStaticPitch; // The number of bytes in a row of static data GUI::Rect mySrcGUIR, myDstGUIR; }; diff --git a/src/common/FrameBufferSDL2.cxx b/src/common/FrameBufferSDL2.cxx index d9338eeb9..61baf8e0b 100644 --- a/src/common/FrameBufferSDL2.cxx +++ b/src/common/FrameBufferSDL2.cxx @@ -317,8 +317,8 @@ void FrameBufferSDL2::setWindowIcon() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -unique_ptr FrameBufferSDL2::createSurface(uInt32 w, uInt32 h, - const uInt32* data) const +unique_ptr + FrameBufferSDL2::createSurface(uInt32 w, uInt32 h, const uInt32* data) const { return make_unique(const_cast(*this), w, h, data); } diff --git a/src/common/FrameBufferSDL2.hxx b/src/common/FrameBufferSDL2.hxx index 74969ed55..31c6871f1 100644 --- a/src/common/FrameBufferSDL2.hxx +++ b/src/common/FrameBufferSDL2.hxx @@ -145,8 +145,8 @@ class FrameBufferSDL2 : public FrameBuffer @param h The requested height of the new surface. @param data If non-null, use the given data values as a static surface */ - unique_ptr createSurface(uInt32 w, uInt32 h, const uInt32* data) - const override; + unique_ptr + createSurface(uInt32 w, uInt32 h, const uInt32* data) const override; /** Grabs or ungrabs the mouse based on the given boolean value. diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index 79afaff06..a23d3db00 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -349,8 +349,8 @@ class FrameBuffer @param h The requested height of the new surface. @param data If non-null, use the given data values as a static surface */ - virtual unique_ptr createSurface(uInt32 w, uInt32 h, - const uInt32* data) const = 0; + virtual unique_ptr + createSurface(uInt32 w, uInt32 h, const uInt32* data) const = 0; /** Grabs or ungrabs the mouse based on the given boolean value.