@kmamal/sdl 0.11.12 → 0.11.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [v0.11.13] - 2025-08-30
9
+
10
+ ### Fixed
11
+
12
+ - Allow `window.native.handle` to be `null` in case `SDL_GetWindowWMInfo` failed.
13
+
8
14
  ## [v0.11.12] - 2025-07-24
9
15
 
10
16
  ### Added
@@ -48,7 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
48
54
 
49
55
  - Started keeping this changelog.
50
56
 
51
- [unreleased]: https://github.com/kmamal/node-sdl/compare/v0.11.12...HEAD
57
+ [unreleased]: https://github.com/kmamal/node-sdl/compare/v0.11.13...HEAD
58
+ [v0.11.13]: https://github.com/kmamal/node-sdl/compare/v0.11.12...v0.11.13
52
59
  [v0.11.12]: https://github.com/kmamal/node-sdl/compare/v0.11.11...v0.11.12
53
60
  [v0.11.11]: https://github.com/kmamal/node-sdl/compare/v0.11.10...v0.11.11
54
61
  [v0.11.10]: https://github.com/kmamal/node-sdl/compare/v0.11.9...v0.11.10
package/README.md CHANGED
@@ -1058,7 +1058,7 @@ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) wi
1058
1058
  ### window.native
1059
1059
 
1060
1060
  - `<object>`
1061
- - `handle : <Buffer>` The platform-specific handle of the window.
1061
+ - `handle : <Buffer>|<null>` The platform-specific handle of the window, or `null` if it can't be determined.
1062
1062
 
1063
1063
  The native type of `handle` is HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux.
1064
1064
  It should work exactly like the [`win.getNativeWindowHandle()`](https://www.electronjs.org/docs/latest/api/browser-window#wingetnativewindowhandle) electron method.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.11.12",
2
+ "version": "0.11.13",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -177,26 +177,41 @@ window::create (const Napi::CallbackInfo &info)
177
177
 
178
178
  Napi::Object native = Napi::Object::New(env);
179
179
 
180
+ bool has_wm_info;
181
+ std::string message_of_failed_wm_info;
180
182
  SDL_SysWMinfo sys_wm_info;
181
183
  SDL_VERSION(&(sys_wm_info.version));
182
- if (SDL_GetWindowWMInfo(window, &sys_wm_info) == SDL_FALSE) {
183
- std::ostringstream message;
184
- message << "SDL_GetWindowWMInfo(" << window_id << ") error: " << SDL_GetError();
184
+ has_wm_info = SDL_GetWindowWMInfo(window, &sys_wm_info) == SDL_TRUE;
185
+ if (!has_wm_info) {
186
+ message_of_failed_wm_info = SDL_GetError();
185
187
  SDL_ClearError();
186
- throw Napi::Error::New(env, message.str());
187
188
  }
188
189
 
189
- NativeWindowHandle native_handle;
190
- #if defined(__LINUX__)
191
- native_handle = sys_wm_info.info.x11.window;
192
- #elif defined(__WIN32__)
193
- native_handle = sys_wm_info.info.win.window;
194
- #elif defined(__MACOSX__)
195
- native_handle = getCocoaWindowHandle(sys_wm_info.info.cocoa.window);
196
- #endif
197
- native.Set("handle", Napi::Buffer<NativeWindowHandle>::Copy(env, &native_handle, 1));
190
+ Napi::Value native_handle;
191
+ if (has_wm_info) {
192
+ NativeWindowHandle _native_handle;
193
+ #if defined(__LINUX__)
194
+ _native_handle = sys_wm_info.info.x11.window;
195
+ #elif defined(__WIN32__)
196
+ _native_handle = sys_wm_info.info.win.window;
197
+ #elif defined(__MACOSX__)
198
+ _native_handle = getCocoaWindowHandle(sys_wm_info.info.cocoa.window);
199
+ #endif
200
+ native_handle = Napi::Buffer<NativeWindowHandle>::Copy(env, &_native_handle, 1);
201
+ }
202
+ else {
203
+ native_handle = env.Null();
204
+ }
205
+ native.Set("handle", native_handle);
198
206
 
199
207
  if (is_opengl) {
208
+ if (!has_wm_info) {
209
+ std::ostringstream message;
210
+ message << "Window has set { opengl: true } but SDL_GetWindowWMInfo failed with: " << message_of_failed_wm_info;
211
+ SDL_ClearError();
212
+ throw Napi::Error::New(env, message.str());
213
+ }
214
+
200
215
  GL_NativeWindow native_gl;
201
216
  #if defined(__LINUX__)
202
217
  native_gl = sys_wm_info.info.x11.window;
@@ -208,6 +223,13 @@ window::create (const Napi::CallbackInfo &info)
208
223
  native.Set("gl", Napi::Buffer<GL_NativeWindow>::Copy(env, &native_gl, 1));
209
224
  }
210
225
  else if (is_webgpu) {
226
+ if (!has_wm_info) {
227
+ std::ostringstream message;
228
+ message << "Window has set { webgpu: true } but SDL_GetWindowWMInfo failed with: " << message_of_failed_wm_info;
229
+ SDL_ClearError();
230
+ throw Napi::Error::New(env, message.str());
231
+ }
232
+
211
233
  GPU_NativeData native_gpu;
212
234
  #if defined(__LINUX__)
213
235
  native_gpu.display = sys_wm_info.info.x11.display;
@@ -547,7 +547,7 @@ export namespace Sdl {
547
547
 
548
548
  readonly opengl: boolean
549
549
  readonly webgpu: boolean
550
- readonly native: { handle: Buffer }
550
+ readonly native: { handle: Buffer | null }
551
551
 
552
552
  readonly maximized: boolean
553
553
  maximize (): void