Skip to content

Commit

Permalink
improvement(sdlafvideorender): fix crash
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Jun 5, 2020
1 parent 32d9f18 commit a61e6b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions framework/render/video/SdlAFVideoRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ SdlAFVideoRender::~SdlAFVideoRender()
if (mVideoTexture != nullptr) {
SDL_DestroyTexture(mVideoTexture);
}

SDL_QuitSubSystem(SDL_INIT_VIDEO);
if (mInitByMe) {
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
}


Expand All @@ -30,10 +31,12 @@ int SdlAFVideoRender::init()
int initRet = 0;
if (SDL_WasInit(SDL_INIT_VIDEO) != SDL_INIT_VIDEO) {
initRet = SDL_Init(SDL_INIT_VIDEO);
mInitByMe = true;
}

if (initRet < 0) {
AF_LOGE("SdlAFVideoRender could not initialize! Error: %s\n", SDL_GetError());
mInitByMe = false;
return initRet;
}

Expand All @@ -49,7 +52,7 @@ int SdlAFVideoRender::init()

int renderWidth = 0;
int renderHeight = 0;
SDL_GetWindowSize(mVideoWindow, &mWindowWidth, &mWindowHeight);
SDL_GL_GetDrawableSize(mVideoWindow, &mWindowWidth, &mWindowHeight);
SDL_GetRendererOutputSize(mVideoRender, &renderWidth, &renderHeight);
float DISPLAY_WIDTH_RATIO = renderWidth * 1.0f / mWindowWidth;
float DISPLAY_HEIGHT_RATIO = renderHeight * 1.0f / mWindowHeight;
Expand Down Expand Up @@ -222,8 +225,7 @@ int SdlAFVideoRender::setScale(Scale scale)
SDL_Rect SdlAFVideoRender::getDestRet()
{
SDL_Rect dstRect{};
SDL_GetWindowSize(mVideoWindow, &mWindowWidth, &mWindowHeight);

SDL_GL_GetDrawableSize(mVideoWindow, &mWindowWidth, &mWindowHeight);
if (mWindowWidth == 0 || mWindowHeight == 0 ||
mVideoWidth == 0 || mVideoHeight == 0) {
dstRect.x = 0;
Expand Down Expand Up @@ -420,12 +422,13 @@ int SdlAFVideoRender::setDisPlay(void *view)
}
if (SDL_WasInit(SDL_INIT_VIDEO) != SDL_INIT_VIDEO) {
SDL_Init(SDL_INIT_VIDEO);
mInitByMe = true;
}
mVideoWindow = SDL_CreateWindowFrom(view);
SDL_ShowWindow(mVideoWindow);

if (mVideoWindow) {
mVideoRender = SDL_CreateRenderer(mVideoWindow, -1, SDL_RENDERER_SOFTWARE);
mVideoRender = SDL_CreateRenderer(mVideoWindow, -1, 0);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion framework/render/video/SdlAFVideoRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SdlAFVideoRender : public IVideoRender, private IVSync::Listener {
std::mutex mRenderMutex;
std::unique_ptr<IVSync> mVSync{nullptr};
std::function<void(int64_t, bool)> mRenderResultCallback = nullptr;

bool mInitByMe{false};
};


Expand Down

0 comments on commit a61e6b2

Please sign in to comment.