We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2365 - SDL_Create and SDL_Destroy
Summary: SDL_Create and SDL_Destroy
Status: CLOSED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.0
Hardware: x86 Windows 7
: P2 critical
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-26 10:11 UTC by SweetLover
Modified: 2014-02-26 01:17 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description SweetLover 2014-01-26 10:11:01 UTC
If you use SDL_CreateWindow, SDL_CreateRenderer and SDL_CreateTexture at the first time, then SDL_RenderClear(ren), SDL_UpdateTexture, SDL_RenderCopy and SDL_RenderPresent will work normally.

However, they can't display picture when you use SDL_CreateWindow, SDL_CreateRenderer and SDL_CreateTexture after the first time that you use SDL_DestroyTexture, SDL_DestroyRender and SDL_DestroyWindow then Create.
Comment 1 SweetLover 2014-01-27 03:11:15 UTC
Yesterday, I have submitted the MFC test project to you.

Now, detail Steps:

1.Initialize the SDL and FFMPEG decoding for video.
2.Create the window by calling[Detail]:
    // Symbol "m_hWnd" is a static picture control handle in MFC
    SDL_Window *win = SDL_CreateWindowFrom(m_hWnd);
    SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED |
SDL_RENDERER_TARGETTEXTURE);
    // symbol "rect" is SDL_Rect.
    SDL_Texture *tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, rect.w, rect.h);
3.Start decoding video thread, work well. SDL show the video.
4.SuspendThread decoding thread, release the window by calling[Detail]:
    SDL_DestroyTexture(tex);
    SDL_DestroyRenderer(ren);
    SDL_DestroyWindow(win);
5.Then create the window again as step 2.
6.Resume decoding video thread, BUG: THE VIDEO DISAPPEARED! IT DISPLAYS NOTHING!

I hope that you can tell me the result whether it's my fault or not soon, thank you.
Comment 2 Gabriel Jacobo 2014-02-12 22:27:35 UTC
Can you post a test case to reproduce?
Comment 3 SweetLover 2014-02-18 03:01:56 UTC
(In reply to Gabriel Jacobo from comment #2)
> Can you post a test case to reproduce?

Unfortunately, I can write a minimal test case without MFC, but I cannot write it to reproduce the bug without video decoding, because the SDL cannot decode video, so I give the error code in following(I can make sure my video decoding works fine, it can display well by Windows GDI, I have tested it):

RECT rt;
SDL_Rect rect;
HWND g_hWnd = GetDlgItem(IDC_PICTURE1)->m_hWnd;
GetClientRect(g_hWnd, &rt);
rect.x =0;
rect.y =0;
rect.w = rt.right - rt.left;
rect.h = rt.bottom - rt.top;

// Create it
SDL_Window *win = SDL_CreateWindowFrom(g_hWnd);
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED |
		SDL_RENDERER_TARGETTEXTURE);
SDL_Texture *tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, rect.w, rect.h);

/* bug begin*/
// Release it
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);

// Create it again
win = SDL_CreateWindowFrom(g_hWnd);
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED |
		SDL_RENDERER_TARGETTEXTURE);
tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, rect.w, rect.h);
/* bug end */

// Display the video, but show blank
/* ffmpeg decoding.. */
SDL_RenderClear(ren);
SDL_UpdateTexture(tex, &rect, pFrameRGB->data[0], pFrameRGB->linesize[0]);
SDL_RenderCopy(ren, tex, NULL, &rect);
SDL_RenderPresent(ren);

if delete code between "bug begin" and "bug end", the video display well, otherwise show blank.
Comment 4 Nader Golbaz 2014-02-25 11:28:26 UTC
SDL_DestroyWindow hides the window. You should add SDL_ShowWindow after SDL_CreateWindowFrom.
Comment 5 Gabriel Jacobo 2014-02-25 12:24:48 UTC
The user reported via email that the solution suggested by Nader Golbaz solves the issue.
Comment 6 SweetLover 2014-02-26 01:17:12 UTC
Thanks a lot. It's my fault that I forget to call SDL_ShowWindow after create it, the truth is that if you call SDL_Destroy, the windows will be hide, so we cannot see it after call SDL_Create again before function SDL_Destroy called.