Giter Site home page Giter Site logo

SDL_CreateWindowFrom handle leak about sdl HOT 9 OPEN

Beyondyxc avatar Beyondyxc commented on August 15, 2024
SDL_CreateWindowFrom handle leak

from sdl.

Comments (9)

Beyondyxc avatar Beyondyxc commented on August 15, 2024

sdl source code

#include "widget_sdl.h"
#include <iostream>

const int FPSCOUNTTIMEMS = 60000;
const int FPSCOUNTTIME = 60;

#define    SDL_USEREVENT_RENDER_IMAGE    0x1001
#define    SDL_USEREVENT_IMAGE_SIZE_CHANGE    0x1002

#ifdef _WIN32
#ifndef bzero
#define    bzero(m,n)        ZeroMemory(m, n)    /**< Mapping bzero() to ZeroMemory() */
#endif
#endif
const int WIDTH_1920 = 1920;
const int HEIGHT_1080 = 1080;
static int player_count_ = 1;
WidgetSDL::WidgetSDL()
{
#ifdef _WIN32
    win_width_ = GetSystemMetrics(SM_CXSCREEN);
    win_height_ = GetSystemMetrics(SM_CYSCREEN);
#else
    win_width_ = WIDTH_1920;
    win_height_ = HEIGHT_1080;
#endif
    player_count_++;
    player_index_ = player_count_;
    SDLRelatedInit();
}

WidgetSDL::~WidgetSDL() {
    OutputDebugString("\n");
    OutputDebugString("Free WidgetSDL\n");
    FreeSDLRes();
    SDLRelatedUninit();
}

bool WidgetSDL::Play() {
    OutputDebugString("\n");
    OutputDebugString("WidgetSDL::Play\n");
    if (sdl_window_ == nullptr) {
        CreateSDLRes();
    }
    return true;
}

void WidgetSDL::Stop() {
    OutputDebugString("\n");
    OutputDebugString("WidgetSDL::Stop\n");
    FreeSDLRes();
}

void WidgetSDL::SetWnd(HWND wnd) {
    OutputDebugString("\n");
    OutputDebugString("WidgetSDL::SetWnd\n");
    wnd_ = wnd;
}

void WidgetSDL::SetSize(int width, int height) {
    win_width_ = width;
    win_height_ = height;
}

void WidgetSDL::SDLRelatedInit() {
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        OutputDebugString("\n");
        OutputDebugString("WidgetSDL::SDLRelatedInit failed\n");
    }
    else {
        OutputDebugString("\n");
        OutputDebugString("WidgetSDL::SDLRelatedInit success\n");
    }

}

void WidgetSDL::SDLRelatedUninit() {
    OutputDebugString("\n");
    OutputDebugString("WidgetSDL::SDL_Quit start\n");
    SDL_Quit();
    OutputDebugString("\n");
    OutputDebugString("WidgetSDL::SDL_Quit end\n");
}

void WidgetSDL::CreateSDLRes() {
    OutputDebugString("\n");
    OutputDebugString("WidgetSDL::CreateSDLRes\n");
	FreeSDLRes();

    if (!wnd_) {
        sdl_window_ = SDL_CreateWindow(u8"webrtc_player_window",  // 窗口标题
            SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,       // 窗口位置
            win_width_, win_height_,                              // 窗口宽高
            SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALLOW_HIGHDPI             // 窗口属性,指定使用OpenGL
        );
    }
    else {
         sdl_window_ = SDL_CreateWindowFrom((void*)wnd_);
    }
    OutputDebugString("\n");
    OutputDebugString("WidgetSDL::CreateSDLRes done\n");
}

void WidgetSDL::FreeSDLRes() {
    FreeSDLTexture();
    FreeSDLRender();
	if (sdl_window_) {
		SDL_DestroyWindow(sdl_window_);
		sdl_window_ = nullptr;
	}
}

void WidgetSDL::CreateSDLTexture() {
    if (!sdl_texture_) {
        if (sdl_renderer_) {
            sdl_texture_ = SDL_CreateTexture(sdl_renderer_, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING,
                WIDTH_1920, HEIGHT_1080);
        }
        else {
            
            return;
        }
    }
    else {
        
    }
}

void WidgetSDL::FreeSDLTexture() {
    
    if (sdl_texture_) {
        SDL_DestroyTexture(sdl_texture_);
        sdl_texture_ = nullptr;
    }
    else {
        
        return;
    }
    
}

void WidgetSDL::CreateSDLRender() {
    if (!sdl_renderer_){
        unsigned int renderer_flags = SDL_RENDERER_ACCELERATED;
        sdl_renderer_ = SDL_CreateRenderer(sdl_window_, -1, renderer_flags);
        SDL_GetWindowSize(sdl_window_, &win_width_, &win_height_);

        SDL_RendererInfo rendererInfo;
        SDL_GetRendererInfo(sdl_renderer_, &rendererInfo);
    }
   
}
void WidgetSDL::FreeSDLRender() {
    if (sdl_renderer_) {
        SDL_DestroyRenderer(sdl_renderer_);
        sdl_renderer_ = nullptr;
    }
    else {
        
    }
}

from sdl.

Beyondyxc avatar Beyondyxc commented on August 15, 2024

QT widget create sdl player source code

temp_player = std::make_unique<PlayerWidget>(this);
    if (temp_player) {
        sdl_player = std::make_unique<WidgetSDL>();
        sdl_player->SetWnd(temp_player->Wnd());
        sdl_player->Play();
        qDebug() << "sdl play create";
    }

from sdl.

Beyondyxc avatar Beyondyxc commented on August 15, 2024

QT widget free sdl player source code:

if (sdl_player) {
        sdl_player->Stop();
        sdl_player.reset();
        qDebug() << "sdl play free";
    }
    if (temp_player) {
        temp_player.reset();
    }

from sdl.

Beyondyxc avatar Beyondyxc commented on August 15, 2024

When I create and release, The window handle of Windows Task Manager is constantly rising, and my platform is Win10, QT is 5.12.5, regardless of whether the external QT window is destroyed or not, creating SDL windows will cause handle leakage

from sdl.

slouken avatar slouken commented on August 15, 2024

Are you calling SDL_PollEvent() to drain the SDL event queue?

from sdl.

Beyondyxc avatar Beyondyxc commented on August 15, 2024

Are you calling SDL_PollEvent() to drain the SDL event queue?

Now I am only using an external QT window to create an SDL window, without involving rendering, and without creating a render and texture, there will be handle leaks. You can take a look at the code I posted

from sdl.

slouken avatar slouken commented on August 15, 2024

If you create an SDL window, you should process SDL events on the thread that created the window. Try that and see if that fixes the issue?

from sdl.

Beyondyxc avatar Beyondyxc commented on August 15, 2024

If you create an SDL window, you should process SDL events on the thread that created the window. Try that and see if that fixes the issue?

I tried using QT's timer to process SDL events during thread timing, but it still doesn't seem to work. Here is my event handling code. I feel like there may be a problem with my usage. Can you provide a standard example

void WidgetSDL::ProcessEvent() {
    OutputDebugString("\n");
    OutputDebugString("WidgetSDL::ProcessEvent\n");
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
        if (event.type == SDL_QUIT) {
            
        }
    }
}

from sdl.

slouken avatar slouken commented on August 15, 2024

This should process events correctly. I'm not sure what's causing the handles to be created.

from sdl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.