dear-imgui-wgpu 0.11.0

WGPU renderer backend for dear-imgui-rs (native + WebAssembly)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
// Multi-viewport support (SDL3 platform backend + WGPU renderer)
//
// This mirrors the existing winit multi-viewport renderer callbacks, but reads
// ImGuiViewport::PlatformHandle as an SDL_WindowID and creates per-viewport
// WGPU surfaces from SDL3 native window handles.

use super::*;
use dear_imgui_rs::internal::RawCast;
use dear_imgui_rs::platform_io::Viewport;
use std::ffi::c_void;
use std::ops::{Deref, DerefMut};
use std::sync::Mutex;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicUsize, Ordering};

use super::sdl3_raw_window_handle::Sdl3SurfaceTarget;

#[cfg(target_arch = "wasm32")]
compile_error!("`multi-viewport-sdl3` is not supported on wasm32 targets.");

/// Per-viewport WGPU data stored in ImGuiViewport::RendererUserData
struct ViewportWgpuData {
    pub device: wgpu::Device,
    pub surface: wgpu::Surface<'static>,
    pub config: wgpu::SurfaceConfiguration,
    pub pending_frame: Option<wgpu::SurfaceTexture>,
    pub pending_reconfigure: bool,
}

static RENDERER_PTR: AtomicUsize = AtomicUsize::new(0);
static RENDERER_BORROWED: AtomicBool = AtomicBool::new(false);
static GLOBAL: Mutex<Option<GlobalHandles>> = Mutex::new(None);

#[derive(Clone)]
struct GlobalHandles {
    instance: Option<wgpu::Instance>,
    adapter: Option<wgpu::Adapter>,
    device: wgpu::Device,
    render_target_format: wgpu::TextureFormat,
}

/// Enable WGPU multi-viewport: set per-viewport callbacks and capture renderer pointer.
pub fn enable(renderer: &mut WgpuRenderer, imgui_context: &mut Context) {
    unsafe {
        let platform_io = imgui_context.platform_io_mut();
        platform_io.set_renderer_create_window(Some(
            renderer_create_window as unsafe extern "C" fn(*mut Viewport),
        ));
        platform_io.set_renderer_destroy_window(Some(
            renderer_destroy_window as unsafe extern "C" fn(*mut Viewport),
        ));
        platform_io.set_renderer_set_window_size(Some(
            renderer_set_window_size
                as unsafe extern "C" fn(*mut Viewport, dear_imgui_rs::sys::ImVec2),
        ));
        platform_io.set_platform_render_window_raw(Some(platform_render_window_sys));
        platform_io.set_platform_swap_buffers_raw(Some(platform_swap_buffers_sys));
    }

    RENDERER_PTR.store(renderer as *mut _ as usize, Ordering::SeqCst);

    if let Some(backend) = renderer.backend_data.as_ref() {
        let mut g = GLOBAL.lock().unwrap_or_else(|poison| poison.into_inner());
        *g = Some(GlobalHandles {
            instance: backend.instance.clone(),
            adapter: backend.adapter.clone(),
            device: backend.device.clone(),
            render_target_format: backend.render_target_format,
        });
    }
}

pub(crate) fn clear_for_drop(renderer: *mut WgpuRenderer) {
    if RENDERER_PTR
        .compare_exchange(renderer as usize, 0, Ordering::SeqCst, Ordering::SeqCst)
        .is_ok()
    {
        let mut g = GLOBAL.lock().unwrap_or_else(|poison| poison.into_inner());
        *g = None;
    }
}

/// Disable WGPU multi-viewport callbacks and clear stored globals (SDL3 platform).
pub fn disable(imgui_context: &mut Context) {
    unsafe {
        let platform_io = imgui_context.platform_io_mut();
        platform_io.set_renderer_create_window(None);
        platform_io.set_renderer_destroy_window(None);
        platform_io.set_renderer_set_window_size(None);
        platform_io.set_platform_render_window_raw(None);
        platform_io.set_platform_swap_buffers_raw(None);
    }
    RENDERER_PTR.store(0, Ordering::SeqCst);
    let mut g = GLOBAL.lock().unwrap_or_else(|poison| poison.into_inner());
    *g = None;
}

/// Convenience helper that disables callbacks and destroys all platform windows.
pub fn shutdown_multi_viewport_support(context: &mut Context) {
    disable(context);
    context.destroy_platform_windows();
}

#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn borrow_renderer() -> Option<RendererBorrowGuard> {
    let ptr = RENDERER_PTR.load(Ordering::SeqCst) as *mut WgpuRenderer;
    if ptr.is_null() {
        return None;
    }
    if RENDERER_BORROWED
        .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
        .is_err()
    {
        eprintln!("[wgpu-mv-sdl3] renderer already mutably borrowed; skipping callback");
        return None;
    }
    Some(RendererBorrowGuard { renderer: ptr })
}

unsafe fn viewport_user_data_mut<'a>(vpm: &'a mut Viewport) -> Option<&'a mut ViewportWgpuData> {
    let data = vpm.renderer_user_data();
    if data.is_null() {
        None
    } else {
        Some(unsafe { &mut *(data as *mut ViewportWgpuData) })
    }
}

struct RendererBorrowGuard {
    renderer: *mut WgpuRenderer,
}

impl Drop for RendererBorrowGuard {
    fn drop(&mut self) {
        RENDERER_BORROWED.store(false, Ordering::SeqCst);
    }
}

impl Deref for RendererBorrowGuard {
    type Target = WgpuRenderer;

    fn deref(&self) -> &Self::Target {
        unsafe { &*self.renderer }
    }
}

impl DerefMut for RendererBorrowGuard {
    fn deref_mut(&mut self) -> &mut Self::Target {
        unsafe { &mut *self.renderer }
    }
}

fn sdl_window_id_from_viewport(vp: &Viewport) -> Option<sdl3_sys::video::SDL_WindowID> {
    let handle = vp.platform_handle();
    if handle.is_null() {
        None
    } else {
        Some(sdl3_sys::video::SDL_WindowID(handle as usize as u32))
    }
}

fn clamp_i32_pixels_to_u32(pixels: i32) -> u32 {
    if pixels > 0 { pixels as u32 } else { 1 }
}

/// Renderer: create per-viewport resources (surface + config)
///
/// # Safety
///
/// Called by Dear ImGui from C with a valid `Viewport*` belonging to the current ImGui context.
#[allow(unsafe_op_in_unsafe_fn)]
pub unsafe extern "C" fn renderer_create_window(vp: *mut Viewport) {
    if vp.is_null() {
        return;
    }
    let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| unsafe {
        mvlog!("[wgpu-mv-sdl3] Renderer_CreateWindow");

        let global = {
            let g = GLOBAL.lock().unwrap_or_else(|poison| poison.into_inner());
            match g.as_ref() {
                Some(g) => g.clone(),
                None => return,
            }
        };

        let vpm = &mut *vp;
        let window_id = match sdl_window_id_from_viewport(vpm) {
            Some(id) => id,
            None => return,
        };

        let target = match Sdl3SurfaceTarget::from_window_id(window_id) {
            Some(t) => t,
            None => return,
        };

        let instance = match &global.instance {
            Some(i) => i.clone(),
            None => return,
        };

        let surface: wgpu::Surface<'static> = {
            // SAFETY: the underlying SDL window and display remain valid for the lifetime of the
            // corresponding ImGui viewport, and Dear ImGui calls `Renderer_DestroyWindow` before
            // the platform destroys the window. Therefore the raw handles remain valid until this
            // surface is dropped.
            let surface_target = match wgpu::SurfaceTargetUnsafe::from_window(&target) {
                Ok(t) => t,
                Err(e) => {
                    eprintln!("[wgpu-mv-sdl3] create_surface handle error: {:?}", e);
                    return;
                }
            };
            match instance.create_surface_unsafe(surface_target) {
                Ok(s) => s,
                Err(e) => {
                    eprintln!("[wgpu-mv-sdl3] create_surface error: {:?}", e);
                    return;
                }
            }
        };

        // Query initial pixel size from SDL3.
        let mut w: i32 = 0;
        let mut h: i32 = 0;
        let raw_window = target.raw_window();
        let ok = sdl3_sys::video::SDL_GetWindowSizeInPixels(raw_window, &mut w, &mut h);
        if !ok {
            return;
        }
        let width = clamp_i32_pixels_to_u32(w);
        let height = clamp_i32_pixels_to_u32(h);

        let config = if let Some(adapter) = &global.adapter {
            let caps = surface.get_capabilities(adapter);
            let format = if caps.formats.contains(&global.render_target_format) {
                global.render_target_format
            } else {
                eprintln!(
                    "[wgpu-mv-sdl3] Surface doesn't support pipeline format {:?}; supported: {:?}. Skipping configure.",
                    global.render_target_format, caps.formats
                );
                return;
            };
            let present_mode = if caps.present_modes.contains(&wgpu::PresentMode::Fifo) {
                wgpu::PresentMode::Fifo
            } else {
                caps.present_modes
                    .get(0)
                    .cloned()
                    .unwrap_or(wgpu::PresentMode::Fifo)
            };
            let alpha_mode = if caps.alpha_modes.contains(&wgpu::CompositeAlphaMode::Opaque) {
                wgpu::CompositeAlphaMode::Opaque
            } else if caps.alpha_modes.contains(&wgpu::CompositeAlphaMode::Auto) {
                wgpu::CompositeAlphaMode::Auto
            } else {
                caps.alpha_modes
                    .get(0)
                    .cloned()
                    .unwrap_or(wgpu::CompositeAlphaMode::Opaque)
            };
            wgpu::SurfaceConfiguration {
                usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
                format,
                width,
                height,
                present_mode,
                alpha_mode,
                view_formats: vec![format],
                desired_maximum_frame_latency: 1,
            }
        } else {
            wgpu::SurfaceConfiguration {
                usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
                format: global.render_target_format,
                width,
                height,
                present_mode: wgpu::PresentMode::Fifo,
                alpha_mode: wgpu::CompositeAlphaMode::Opaque,
                view_formats: vec![global.render_target_format],
                desired_maximum_frame_latency: 1,
            }
        };

        surface.configure(&global.device, &config);

        let data = ViewportWgpuData {
            device: global.device.clone(),
            surface,
            config,
            pending_frame: None,
            pending_reconfigure: false,
        };
        vpm.set_renderer_user_data(Box::into_raw(Box::new(data)) as *mut c_void);
    }));
    if res.is_err() {
        eprintln!("[wgpu-mv-sdl3] panic in Renderer_CreateWindow");
        std::process::abort();
    }
}

/// Renderer: destroy per-viewport resources
///
/// # Safety
///
/// Called by Dear ImGui from C with a valid `Viewport*` belonging to the current ImGui context.
#[allow(unsafe_op_in_unsafe_fn)]
pub unsafe extern "C" fn renderer_destroy_window(vp: *mut Viewport) {
    if vp.is_null() {
        return;
    }
    let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| unsafe {
        mvlog!("[wgpu-mv-sdl3] Renderer_DestroyWindow");
        let vpm = &mut *vp;
        let data = vpm.renderer_user_data();
        if !data.is_null() {
            let _boxed: Box<ViewportWgpuData> = Box::from_raw(data as *mut ViewportWgpuData);
            vpm.set_renderer_user_data(std::ptr::null_mut());
        }
    }));
    if res.is_err() {
        eprintln!("[wgpu-mv-sdl3] panic in Renderer_DestroyWindow");
        std::process::abort();
    }
}

/// Renderer: notify new size
///
/// # Safety
///
/// Called by Dear ImGui from C with a valid `Viewport*` belonging to the current ImGui context.
#[allow(unsafe_op_in_unsafe_fn)]
pub unsafe extern "C" fn renderer_set_window_size(
    vp: *mut Viewport,
    size: dear_imgui_rs::sys::ImVec2,
) {
    if vp.is_null() {
        return;
    }
    let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| unsafe {
        mvlog!(
            "[wgpu-mv-sdl3] Renderer_SetWindowSize to ({}, {})",
            size.x,
            size.y
        );
        let global = {
            let g = GLOBAL.lock().unwrap_or_else(|poison| poison.into_inner());
            match g.as_ref() {
                Some(g) => g.clone(),
                None => return,
            }
        };
        let vpm = &mut *vp;
        let scale = vpm.framebuffer_scale();
        if let Some(data) = viewport_user_data_mut(vpm) {
            let sx = if scale[0].is_finite() && scale[0] > 0.0 {
                scale[0]
            } else {
                1.0
            };
            let sy = if scale[1].is_finite() && scale[1] > 0.0 {
                scale[1]
            } else {
                1.0
            };
            let new_w = (size.x * sx).max(1.0).round() as u32;
            let new_h = (size.y * sy).max(1.0).round() as u32;
            if data.config.width != new_w || data.config.height != new_h {
                data.config.width = new_w;
                data.config.height = new_h;
                data.surface.configure(&global.device, &data.config);
            }
        }
    }));
    if res.is_err() {
        eprintln!("[wgpu-mv-sdl3] panic in Renderer_SetWindowSize");
        std::process::abort();
    }
}

/// Renderer: render viewport draw data into its surface
///
/// # Safety
///
/// Called by Dear ImGui from C with a valid `Viewport*` belonging to the current ImGui context.
#[allow(unsafe_op_in_unsafe_fn)]
pub unsafe extern "C" fn renderer_render_window(vp: *mut Viewport, _render_arg: *mut c_void) {
    if vp.is_null() {
        return;
    }
    let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| unsafe {
        mvlog!("[wgpu-mv-sdl3] Renderer_RenderWindow");

        let Some(mut renderer) = borrow_renderer() else {
            return;
        };
        let (device, queue) = match renderer.backend_data.as_ref() {
            Some(b) => (b.device.clone(), b.queue.clone()),
            None => return,
        };

        let vpm = &mut *vp;
        let window_id = sdl_window_id_from_viewport(vpm);
        let raw_dd = vpm.draw_data();
        if raw_dd.is_null() {
            return;
        }
        // SAFETY: Dear ImGui guarantees `raw_dd` is valid during render callbacks.
        let draw_data: &dear_imgui_rs::render::DrawData =
            dear_imgui_rs::render::DrawData::from_raw(&*raw_dd);

        if let Some(data) = viewport_user_data_mut(vpm) {
            let fb_w = data.config.width;
            let fb_h = data.config.height;
            #[cfg(feature = "wgpu-29")]
            let (frame, reconfigure_after_present) = match data.surface.get_current_texture() {
                wgpu::CurrentSurfaceTexture::Success(frame) => (frame, false),
                wgpu::CurrentSurfaceTexture::Suboptimal(frame) => (frame, true),
                wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => {
                    // Reconfigure from actual SDL3 pixel size and retry next frame.
                    if let Some(window_id) = window_id {
                        if let Some(target) = Sdl3SurfaceTarget::from_window_id(window_id) {
                            let raw_window = target.raw_window();
                            let mut w: i32 = 0;
                            let mut h: i32 = 0;
                            if sdl3_sys::video::SDL_GetWindowSizeInPixels(
                                raw_window, &mut w, &mut h,
                            ) {
                                let w = clamp_i32_pixels_to_u32(w);
                                let h = clamp_i32_pixels_to_u32(h);
                                data.config.width = w;
                                data.config.height = h;
                                data.surface.configure(&device, &data.config);
                            }
                        }
                    }
                    return;
                }
                wgpu::CurrentSurfaceTexture::Timeout | wgpu::CurrentSurfaceTexture::Occluded => {
                    return;
                }
                wgpu::CurrentSurfaceTexture::Validation => {
                    eprintln!("[wgpu-mv-sdl3] get_current_texture failed with a validation error");
                    return;
                }
            };
            #[cfg(any(feature = "wgpu-27", feature = "wgpu-28"))]
            let (frame, reconfigure_after_present) = match data.surface.get_current_texture() {
                Ok(frame) => (frame, false),
                Err(wgpu::SurfaceError::Outdated) | Err(wgpu::SurfaceError::Lost) => {
                    // Reconfigure from actual SDL3 pixel size and retry next frame.
                    if let Some(window_id) = window_id {
                        if let Some(target) = Sdl3SurfaceTarget::from_window_id(window_id) {
                            let raw_window = target.raw_window();
                            let mut w: i32 = 0;
                            let mut h: i32 = 0;
                            if sdl3_sys::video::SDL_GetWindowSizeInPixels(
                                raw_window, &mut w, &mut h,
                            ) {
                                let w = clamp_i32_pixels_to_u32(w);
                                let h = clamp_i32_pixels_to_u32(h);
                                data.config.width = w;
                                data.config.height = h;
                                data.surface.configure(&data.device, &data.config);
                            }
                        }
                    }
                    return;
                }
                Err(wgpu::SurfaceError::Timeout) => return,
                Err(e) => {
                    eprintln!("[wgpu-mv-sdl3] get_current_texture error: {:?}", e);
                    return;
                }
            };

            let view = frame
                .texture
                .create_view(&wgpu::TextureViewDescriptor::default());

            let render_block = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
                let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
                    label: Some("dear-imgui-wgpu::viewport-encoder"),
                });
                {
                    let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
                        label: Some("dear-imgui-wgpu::viewport-pass"),
                        color_attachments: &[Some(wgpu::RenderPassColorAttachment {
                            view: &view,
                            resolve_target: None,
                            ops: wgpu::Operations {
                                load: wgpu::LoadOp::Clear(renderer.viewport_clear_color()),
                                store: wgpu::StoreOp::Store,
                            },
                            depth_slice: None,
                        })],
                        depth_stencil_attachment: None,
                        occlusion_query_set: None,
                        #[cfg(any(feature = "wgpu-28", feature = "wgpu-29"))]
                        multiview_mask: None,
                        timestamp_writes: None,
                    });

                    if let Err(e) = renderer.render_draw_data_with_fb_size_ex(
                        &draw_data,
                        &mut render_pass,
                        fb_w,
                        fb_h,
                        false,
                    ) {
                        eprintln!("[wgpu-mv-sdl3] render_draw_data(with_fb) error: {:?}", e);
                    }
                }
                queue.submit(std::iter::once(encoder.finish()));
            }));

            if render_block.is_err() {
                eprintln!(
                    "[wgpu-mv-sdl3] panic during viewport render block; skipping present for this viewport"
                );
                return;
            }

            data.pending_frame = Some(frame);
            data.pending_reconfigure = reconfigure_after_present;
        }
    }));
    if res.is_err() {
        eprintln!("[wgpu-mv-sdl3] panic in Renderer_RenderWindow");
        std::process::abort();
    }
}

/// Renderer: present frame for viewport surface
///
/// # Safety
///
/// Called by Dear ImGui from C with a valid `Viewport*` belonging to the current ImGui context.
#[allow(unsafe_op_in_unsafe_fn)]
pub unsafe extern "C" fn renderer_swap_buffers(vp: *mut Viewport, _render_arg: *mut c_void) {
    if vp.is_null() {
        return;
    }
    let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| unsafe {
        mvlog!("[wgpu-mv-sdl3] Renderer_SwapBuffers");
        let vpm = &mut *vp;
        if let Some(data) = viewport_user_data_mut(vpm) {
            if let Some(frame) = data.pending_frame.take() {
                frame.present();
                if data.pending_reconfigure {
                    data.surface.configure(&data.device, &data.config);
                    data.pending_reconfigure = false;
                }
            }
        }
    }));
    if res.is_err() {
        eprintln!("[wgpu-mv-sdl3] panic in Renderer_SwapBuffers");
        std::process::abort();
    }
}

/// Raw sys-platform wrapper to avoid typed trampolines.
///
/// # Safety
///
/// Called by Dear ImGui from C with a valid `ImGuiViewport*` belonging to the current ImGui context.
#[allow(unsafe_op_in_unsafe_fn)]
pub unsafe extern "C" fn platform_render_window_sys(
    vp: *mut dear_imgui_rs::sys::ImGuiViewport,
    arg: *mut c_void,
) {
    if vp.is_null() {
        return;
    }
    let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| unsafe {
        renderer_render_window(vp as *mut Viewport, arg);
    }));
    if res.is_err() {
        eprintln!("[wgpu-mv-sdl3] panic in Platform_RenderWindow");
        std::process::abort();
    }
}

/// Raw sys-platform wrapper to avoid typed trampolines.
///
/// # Safety
///
/// Called by Dear ImGui from C with a valid `ImGuiViewport*` belonging to the current ImGui context.
#[allow(unsafe_op_in_unsafe_fn)]
pub unsafe extern "C" fn platform_swap_buffers_sys(
    vp: *mut dear_imgui_rs::sys::ImGuiViewport,
    arg: *mut c_void,
) {
    if vp.is_null() {
        return;
    }
    let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| unsafe {
        renderer_swap_buffers(vp as *mut Viewport, arg);
    }));
    if res.is_err() {
        eprintln!("[wgpu-mv-sdl3] panic in Platform_SwapBuffers");
        std::process::abort();
    }
}