Comments (9)
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.
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.
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.
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.
Are you calling SDL_PollEvent() to drain the SDL event queue?
from sdl.
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.
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.
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.
This should process events correctly. I'm not sure what's causing the handles to be created.
from sdl.
Related Issues (20)
- define of SDL_GetKeyboardState cannot avoid discarded-qualifiers warning HOT 4
- [Question - SDL2] Opt-out of "forcing X11" mech with GLEW&Co? HOT 4
- SDL3: SDL_GetDisplayBounds fails for 0th display HOT 1
- New temporary memory management can't work with threads HOT 1
- `SDL_GetWindowSizeInPixels` may fail HOT 1
- SDL_RenderTexture9Grid enhancement / freature request HOT 1
- Issue with FPS Capping at Monitor Refresh Rate Even When VSync is Disabled HOT 3
- Occasional segfault in testautomation: mouse_warpMouseInWindow HOT 7
- [SDL3] opengl issue HOT 2
- testautomation --filter render_testBlendModes fails with vulkan renderer HOT 1
- [SDL3] testffmpeg render issue HOT 1
- Window content does not exactly fit window size HOT 6
- SDL_Log does not write to Emscripten console HOT 2
- Long SDL_Init() time when Haptics enabled HOT 4
- SDL3 - iOS needs SDL_HINT_MOUSE_EMULATE_WARP_WITH_RELATIVE=0 if mouse pointer is hidden HOT 12
- Pushes on my fork of SDL now trigger the build actions HOT 5
- Android SDL_AUDIO_DISABLED = undefined symbols OPENSLES_PauseDevices, AAUDIO_PauseDevices, OPENSLES_ResumeDevices, AAUDIO_ResumeDevices HOT 1
- SDL3 build failing under Windows MSYS2 + MINGW64 HOT 1
- Android Rumble Crash joystick->hwdata == null if rumble attempted and GamePad disconnects HOT 3
- Memory Leak in SDL_ShowOpenFileDialog with File Selection on Windows HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdl.