From f6910bc1e0c413441d3176c8568d132eea160621 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 9 Feb 2026 22:25:52 +0100 Subject: [PATCH 1/6] Update rcore_drm.c --- src/platforms/rcore_drm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index 68431030b..6d3394f69 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -1469,7 +1469,7 @@ int InitPlatform(void) if (!eglChooseConfig(platform.device, framebufferAttribs, configs, numConfigs, &matchingNumConfigs)) { TRACELOG(LOG_WARNING, "DISPLAY: Failed to choose EGL config: 0x%x", eglGetError()); - free(configs); + RL_FREE(configs); return -1; } From e67dc15a52f404f811ab9064225f5dc77258d521 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 9 Feb 2026 22:25:55 +0100 Subject: [PATCH 2/6] Update rcore_desktop_glfw.c --- src/platforms/rcore_desktop_glfw.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index e3078dacf..b13018576 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1049,14 +1049,14 @@ Image GetClipboardImage(void) #if defined(SUPPORT_CLIPBOARD_IMAGE) #if defined(_WIN32) unsigned long long int dataSize = 0; - void *fileData = NULL; + void *bmpData = NULL; int width = 0; int height = 0; - fileData = (void *)Win32GetClipboardImageData(&width, &height, &dataSize); + bmpData = (void *)Win32GetClipboardImageData(&width, &height, &dataSize); - if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data."); - else image = LoadImageFromMemory(".bmp", (const unsigned char *)fileData, (int)dataSize); + if (bmpData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data."); + else image = LoadImageFromMemory(".bmp", (const unsigned char *)bmpData, (int)dataSize); #else TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); #endif From 9861baf4b7aa0b6061738c5a795890a2f9ae1ce5 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 9 Feb 2026 22:26:07 +0100 Subject: [PATCH 3/6] Update textures_framebuffer_rendering.c --- examples/textures/textures_framebuffer_rendering.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/textures/textures_framebuffer_rendering.c b/examples/textures/textures_framebuffer_rendering.c index 484192739..097ae1f2f 100644 --- a/examples/textures/textures_framebuffer_rendering.c +++ b/examples/textures/textures_framebuffer_rendering.c @@ -148,6 +148,7 @@ int main(void) //-------------------------------------------------------------------------------------- UnloadRenderTexture(observerTarget); UnloadRenderTexture(subjectTarget); + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- From f190c6a4d479f6a8ee7ccf03cebe16848512b056 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 9 Feb 2026 22:27:16 +0100 Subject: [PATCH 4/6] Update rcore.c --- src/rcore.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rcore.c b/src/rcore.c index e6338367c..4568477d2 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -13,6 +13,7 @@ * - Linux (X11/Wayland desktop mode) * - Others (not tested) * > PLATFORM_DESKTOP_RGFW (RGFW backend): +* > PLATFORM_DESKTOP_WIN32 (native Win32): * - Windows (Win32, Win64) * - Linux (X11/Wayland desktop mode) * - macOS/OSX (x64, arm64) From 84f75785eeebc43a2c96cd4fcd3c21150027ebc3 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 9 Feb 2026 22:29:13 +0100 Subject: [PATCH 5/6] Update rcore.c --- src/rcore.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rcore.c b/src/rcore.c index 4568477d2..49a928372 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -13,16 +13,18 @@ * - Linux (X11/Wayland desktop mode) * - Others (not tested) * > PLATFORM_DESKTOP_RGFW (RGFW backend): -* > PLATFORM_DESKTOP_WIN32 (native Win32): * - Windows (Win32, Win64) * - Linux (X11/Wayland desktop mode) * - macOS/OSX (x64, arm64) * - Others (not tested) -* > PLATFORM_WEB_RGFW: +* > PLATFORM_DESKTOP_WIN32 (native Win32): +* - Windows (Win32, Win64) * > PLATFORM_WEB (GLFW + Emscripten): * - HTML5 (WebAssembly) * > PLATFORM_WEB_EMSCRIPTEN (Emscripten): * - HTML5 (WebAssembly) +* > PLATFORM_WEB_RGFW (Emscripten): +* - HTML5 (WebAssembly) * > PLATFORM_DRM (native DRM): * - Raspberry Pi 0-5 (DRM/KMS) * - Linux DRM subsystem (KMS mode) From 7e59e1d93d602c9b71c0382d2c989167d5e432bb Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 9 Feb 2026 22:29:47 +0100 Subject: [PATCH 6/6] REVIEWED: Formating --- src/external/win32_clipboard.h | 103 +++++++++++++++------------------ 1 file changed, 47 insertions(+), 56 deletions(-) diff --git a/src/external/win32_clipboard.h b/src/external/win32_clipboard.h index 1f9a27521..75cd720a9 100644 --- a/src/external/win32_clipboard.h +++ b/src/external/win32_clipboard.h @@ -4,7 +4,7 @@ #ifndef WIN32_CLIPBOARD_ #define WIN32_CLIPBOARD_ -unsigned char* Win32GetClipboardImageData(int* width, int* height, unsigned long long int *dataSize); +unsigned char *Win32GetClipboardImageData(int *width, int *height, unsigned long long int *dataSize); #endif // WIN32_CLIPBOARD_ #ifdef WIN32_CLIPBOARD_IMPLEMENTATION @@ -92,7 +92,6 @@ unsigned char* Win32GetClipboardImageData(int* width, int* height, unsigned long typedef int WINBOOL; - #if !defined(_WINUSER_) || !defined(WINUSER_ALREADY_INCLUDED) WINUSERAPI WINBOOL WINAPI OpenClipboard(HWND hWndNewOwner); WINUSERAPI WINBOOL WINAPI CloseClipboard(VOID); @@ -170,8 +169,7 @@ typedef struct tagRGBQUAD { } RGBQUAD, *LPRGBQUAD; #endif - -// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/4e588f70-bd92-4a6f-b77f-35d0feaf7a57 +// REF: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/4e588f70-bd92-4a6f-b77f-35d0feaf7a57 #define BI_RGB 0x0000 #define BI_RLE8 0x0001 #define BI_RLE4 0x0002 @@ -184,10 +182,10 @@ typedef struct tagRGBQUAD { #endif -// https://learn.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats +// REF: https://learn.microsoft.com/en-us/windows/win32/dataxchg/standard-clipboard-formats #define CF_DIB 8 -// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setsystemcursor +// REF: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setsystemcursor // #define OCR_NORMAL 32512 // Normal select // #define OCR_IBEAM 32513 // Text select // #define OCR_WAIT 32514 // Busy @@ -202,36 +200,37 @@ typedef struct tagRGBQUAD { // #define OCR_HAND 32649 // Link select // #define OCR_APPSTARTING 32650 // +static BOOL OpenClipboardRetrying(HWND handle); // Open clipboard with a number of retries +static int GetPixelDataOffset(BITMAPINFOHEADER bih); //---------------------------------------------------------------------------------- // Module Internal Functions Declaration //---------------------------------------------------------------------------------- - - -static BOOL OpenClipboardRetrying(HWND handle); // Open clipboard with a number of retries -static int GetPixelDataOffset(BITMAPINFOHEADER bih); - -unsigned char* Win32GetClipboardImageData(int* width, int* height, unsigned long long int *dataSize) +unsigned char *Win32GetClipboardImageData(int *width, int *height, unsigned long long int *dataSize) { HWND win = NULL; // Get from somewhere but is doesnt seem to matter - const char* msgString = ""; + const char *msgString = ""; int severity = LOG_INFO; - BYTE* bmpData = NULL; - if (!OpenClipboardRetrying(win)) { + BYTE *bmpData = NULL; + + if (!OpenClipboardRetrying(win)) + { severity = LOG_ERROR; msgString = "Couldn't open clipboard"; goto end; } HGLOBAL clipHandle = (HGLOBAL)GetClipboardData(CF_DIB); - if (!clipHandle) { + if (!clipHandle) + { severity = LOG_ERROR; msgString = "Clipboard data is not an Image"; goto close; } BITMAPINFOHEADER *bmpInfoHeader = (BITMAPINFOHEADER *)GlobalLock(clipHandle); - if (!bmpInfoHeader) { + if (!bmpInfoHeader) + { // Mapping from HGLOBAL to our local *address space* failed severity = LOG_ERROR; msgString = "Clipboard data failed to be locked"; @@ -242,7 +241,8 @@ unsigned char* Win32GetClipboardImageData(int* width, int* height, unsigned long *height = bmpInfoHeader->biHeight; SIZE_T clipDataSize = GlobalSize(clipHandle); - if (clipDataSize < sizeof(BITMAPINFOHEADER)) { + if (clipDataSize < sizeof(BITMAPINFOHEADER)) + { // Format CF_DIB needs space for BITMAPINFOHEADER struct. msgString = "Clipboard has Malformed data"; severity = LOG_ERROR; @@ -259,31 +259,29 @@ unsigned char* Win32GetClipboardImageData(int* width, int* height, unsigned long // //--------------------------------------------------------------------------------// - BITMAPFILEHEADER bmpFileHeader = {0}; + BITMAPFILEHEADER bmpFileHeader = { 0 }; SIZE_T bmpFileSize = sizeof(bmpFileHeader) + clipDataSize; *dataSize = bmpFileSize; - bmpFileHeader.bfType = 0x4D42; //https://stackoverflow.com/questions/601430/multibyte-character-constants-and-bitmap-file-header-type-constants#601536 + bmpFileHeader.bfType = 0x4D42; // REF: https://stackoverflow.com/questions/601430/multibyte-character-constants-and-bitmap-file-header-type-constants#601536 bmpFileHeader.bfSize = (DWORD)bmpFileSize; // Up to 4GB works fine bmpFileHeader.bfOffBits = sizeof(bmpFileHeader) + pixelOffset; - // - // Each process has a default heap provided by the system + // WARNING: Each process has a default heap provided by the system // Memory objects allocated by GlobalAlloc and LocalAlloc are in private, - // committed pages with read/write access that cannot be accessed by other processes. + // committed pages with read/write access that cannot be accessed by other processes // // This may be wrong since we might be allocating in a DLL and freeing from another module, the main application // that may cause heap corruption. We could create a FreeImage function - // - bmpData = (BYTE *)malloc(sizeof(bmpFileHeader) + clipDataSize); + bmpData = (BYTE *)RL_MALLOC(sizeof(bmpFileHeader) + clipDataSize); // First we add the header for a bmp file - memcpy(bmpData, &bmpFileHeader, sizeof(bmpFileHeader)); + memcpy(bmpData, &bmpFileHeader, sizeof(bmpFileHeader)); // Add BMP file header data // Then we add the header for the bmp itself + the pixel data - memcpy(bmpData + sizeof(bmpFileHeader), bmpInfoHeader, clipDataSize); + memcpy(bmpData + sizeof(bmpFileHeader), bmpInfoHeader, clipDataSize); // Add BMP info header data + msgString = "Clipboad image acquired successfully"; - unlock: GlobalUnlock(clipHandle); close: @@ -291,6 +289,7 @@ close: end: TRACELOG(severity, msgString); + return bmpData; } @@ -298,65 +297,57 @@ static BOOL OpenClipboardRetrying(HWND hWnd) { static const int maxTries = 20; static const int sleepTimeMS = 60; - for (int _ = 0; _ < maxTries; ++_) + + for (int i = 0; i < maxTries; i++) { // Might be being hold by another process // Or yourself forgot to CloseClipboard - if (OpenClipboard(hWnd)) { - return true; - } + if (OpenClipboard(hWnd)) return true; + Sleep(sleepTimeMS); } + return false; } -// Based off of researching microsoft docs and reponses from this question https://stackoverflow.com/questions/30552255/how-to-read-a-bitmap-from-the-windows-clipboard#30552856 -// https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader // Get the byte offset where does the pixels data start (from a packed DIB) +// REF: https://stackoverflow.com/questions/30552255/how-to-read-a-bitmap-from-the-windows-clipboard#30552856 +// REF: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader static int GetPixelDataOffset(BITMAPINFOHEADER bih) { int offset = 0; const unsigned int rgbaSize = sizeof(RGBQUAD); - // biSize Specifies the number of bytes required by the structure + // NOTE: biSize specifies the number of bytes required by the structure // We expect to always be 40 because it should be packed - if (40 == bih.biSize && 40 == sizeof(BITMAPINFOHEADER)) + if ((40 == bih.biSize) && (40 == sizeof(BITMAPINFOHEADER))) { - // - // biBitCount Specifies the number of bits per pixel. + // NOTE: biBitCount specifies the number of bits per pixel. // Might exist some bit masks *after* the header and *before* the pixel offset // we're looking, but only if we have more than // 8 bits per pixel, so we need to ajust for that - // if (bih.biBitCount > 8) { // if bih.biCompression is RBG we should NOT offset more - if (bih.biCompression == BI_BITFIELDS) - { - offset += 3 * rgbaSize; - } else if (bih.biCompression == 6 /* BI_ALPHABITFIELDS */) + if (bih.biCompression == BI_BITFIELDS) offset += 3*rgbaSize; + else if (bih.biCompression == 6) // BI_ALPHABITFIELDS { - // Not widely supported, but valid. - offset += 4 * rgbaSize; + // Not widely supported, but valid + offset += 4*rgbaSize; } } } - // - // biClrUsed Specifies the number of color indices in the color table that are actually used by the bitmap. + // NOTE: biClrUsed specifies the number of color indices in the color table that are actually used by the bitmap // If this value is zero, the bitmap uses the maximum number of colors - // corresponding to the value of the biBitCount member for the compression mode specified by biCompression. + // corresponding to the value of the biBitCount member for the compression mode specified by biCompression // If biClrUsed is nonzero and the biBitCount member is less than 16 // the biClrUsed member specifies the actual number of colors - // - if (bih.biClrUsed > 0) { - offset += bih.biClrUsed * rgbaSize; - } else { - if (bih.biBitCount < 16) - { - offset = offset + (rgbaSize << bih.biBitCount); - } + if (bih.biClrUsed > 0) offset += bih.biClrUsed*rgbaSize; + else + { + if (bih.biBitCount < 16) offset = offset + (rgbaSize << bih.biBitCount); } return bih.biSize + offset;