• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 44411886896

18 Nov 2026 10:28PM UTC coverage: 61.44% (-0.03%) from 61.472%
44411886896

push

github

jcelerier
flatpak: take onnxruntime from NuGet

github.com/microsoft/onnxruntime and its release archives were taken down
on 2026-11-17. The Microsoft.ML.OnnxRuntime NuGet package carries the same
binaries for both x86_64 and aarch64; install its runtime into the same
/app include/lib layout as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

261552 of 791694 branches covered (33.04%)

267774 of 435829 relevant lines covered (61.44%)

724498.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.48
/src/app/main.cpp
1
// This is an open source non-commercial project. Dear PVS-Studio, please check
2
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3

4
// clang-format off
5
#if defined(_WIN32)
6
#if !defined(_MSC_VER)
7
#include <ntdef.h>
8
#include <windows.h>
9
#include <mmsystem.h>
10
extern "C" NTSYSAPI NTSTATUS NTAPI NtSetTimerResolution(
11
    ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution);
12
#else
13
#include <Windows.h>
14
#include <mmsystem.h>
15
extern "C" __declspec(dllimport) LONG __stdcall NtSetTimerResolution(
16
    ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution);
17

18
extern "C" int gettimeofday(struct timeval* tv, struct timezone* tz)
19
{
20
  return 0;
21
}
22
extern "C" void ___chkstk_ms(void) { }
23

24
#include <cmath>
25
extern "C" void sincos(double x, double* sin, double* cos)
26
{
27
  *sin = std::sin(x);
28
  *cos = std::cos(x);
29
}
30
#endif
31

32
#include <exception>
33
#include <propsys.h>
34
#include <shellapi.h>
35
#include <shobjidl.h>
36

37
#include <string>
38
#if defined(SCORE_HAS_CPP_WINRT)
39
#include <winrt/Windows.Foundation.h>
40
#else
41
#include <objbase.h>
42
namespace score::compat
43
{
44
inline void uninit_apartment() noexcept
45
{
46
  CoUninitialize();
47
}
48
inline void init_apartment_sta() noexcept
49
{
50
  CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
51
}
52
}
53
#endif
54
// MinGW's rpcdce.h, pulled in by the shell headers, defines uuid_t as UUID,
55
// which turns score::uuid_t into score::UUID.
56
#if defined(uuid_t)
57
#undef uuid_t
58
#endif
59
#endif
60
// clang-format on
61

62
#include "Application.hpp"
63

64
#include <score/widgets/MessageBox.hpp>
65
#include <score/gfx/OpenGL.hpp>
66

67
#include <ossia/detail/config.hpp>
68

69
#include <ossia/detail/disable_fpe.hpp>
70
#include <ossia/detail/thread.hpp>
71

72
#include <QApplication>
73
#include <QDir>
74
#include <QItemSelection>
75
#include <QPixmapCache>
76
#include <QStandardPaths>
77
#include <QSurfaceFormat>
78
#include <QTimer>
79
#include <qnamespace.h>
80
#if defined(_WIN32)
81
#include <QPlatformSurfaceEvent>
82
#include <QWindow>
83
#endif
84

85
#include <clocale>
86
#include <cstdio>
87
#include <cstdlib>
88

89
#if QT_WEBVIEW_LIB
90
#include <QtWebView>
91
#endif
92
#ifndef QT_NO_OPENGL
93
#include <QOffscreenSurface>
94
#include <QOpenGLContext>
95
#include <QOpenGLFunctions>
96
#endif
97
/*
98
#if __has_include(<valgrind/callgrind.h>)
99
#include <QMessageBox>
100
#include <QTimer>
101

102
#include <valgrind/callgrind.h>
103
#endif
104
*/
105
#if defined(__linux__)
106
#include <dlfcn.h>
107
#if !_GNU_SOURCE
108
#define _GNU_SOURCE 1
109
#endif
110
#include <sys/resource.h>
111

112
#include <link.h>
113
#define HAS_RLIMIT 1
114
#endif
115

116
#if __has_include(<linux/kd.h>)
117
#include <linux/kd.h>
118
#include <sys/ioctl.h>
119

120
#include <fcntl.h>
121
#include <unistd.h>
122
#endif
123

124
#if defined(__linux__)
125
using X11ErrorHandler = int (*)(void*, void*);
126
using XSetErrorHandler_ptr = X11ErrorHandler (*)(X11ErrorHandler);
127

128
static struct
129
{
130
  bool run_under_x11{};
131
  bool xwayland{};
132
  void* gtk2{};
133
  void* gtk3{};
134
  void* gtk4{};
135
  void* gdk_x11{};
136
  void* x11{};
137
  XSetErrorHandler_ptr x11_set_error_handler{};
138
} helper_dylibs;
139
#endif
140

141
#if defined(__SSE3__)
142
#include <pmmintrin.h>
143
#endif
144

145
#if defined(__has_feature)
146
#if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__)
147
#define __SANITIZE_ADDRESS__ 1
148
#endif
149
#endif
150

151
#if defined(__APPLE__)
152
struct NSAutoreleasePool;
153

154
#include <sys/resource.h>
155

156
#define HAS_RLIMIT 1
157
#include <CoreFoundation/CFNumber.h>
158
#include <CoreFoundation/CFPreferences.h>
159
void disableAppRestore()
160
{
161
  CFPreferencesSetAppValue(
162
      CFSTR("NSQuitAlwaysKeepsWindows"), kCFBooleanFalse,
163
      kCFPreferencesCurrentApplication);
164

165
  CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
166
}
167

168
void ensureDyldPath()
169
{
170
  auto e = qEnvironmentVariable("DYLD_LIBRARY_PATH");
171
  if(e.isEmpty() || e == "/usr/lib/system/introspection")
172
  {
173
    return;
174
  }
175
  else
176
  {
177
    fprintf(
178
        stderr,
179
        "Fatal error: DYLD_LIBRARY_PATH must not be set on macOS.\n"
180
        "See https://github.com/ossia/score/issues/1711\n\n"
181
        "If using Qt Creator, simply go in Projects and\n"
182
        "uncheck the 'Add library search path to DYLD_LIBRARY_PATH and "
183
        "DYLD_FRAMEWORK_PATH'\n"
184
        "checkbox on the execution tab.\n\n"
185
        "Current DYLD_LIBRARY_PATH: '%s'\n",
186
        e.toStdString().c_str());
187

188
    // If you see this comment, you are allowed to remove it on your dev
189
    // build but be aware that you will likely hit very spurious random
190
    // crashes, for instance when a PNG gets loaded or when opening a file
191
    // dialog
192
    exit(1);
193
  }
194
}
195

196
// Defined in mac_main.m
197
extern "C" void disableAppNap();
198
#endif
199

200
extern "C" {
201
Q_DECL_EXPORT short NvOptimusEnablement = 1;
202
Q_DECL_EXPORT int AmdPowerXpressRequestHighPerformance = 1;
203
}
204

205
static bool has_non_nvidia_gpu()
×
206
{
207
#if defined(__linux__)
208
  QDir drmDir("/sys/class/drm");
×
209

210
  if(!drmDir.exists())
×
211
    return false;
×
212

213
  drmDir.setNameFilters({"card[0-9]*"});
×
214

215
  const QFileInfoList entries
216
      = drmDir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
×
217

218
  for(const QFileInfo& entry : entries)
×
219
  {
220
    if(QFile vendorFile(entry.absoluteFilePath() + "/device/vendor");
×
221
       vendorFile.open(QIODevice::ReadOnly | QIODevice::Text))
×
222
    {
223
      const auto vid = QString::fromUtf8(vendorFile.readAll()).trimmed();
×
224

225
      // nvidia vendor id
226
      if(vid.compare("0x10de", Qt::CaseInsensitive) != 0)
×
227
        return true;
×
228
    }
×
229
  }
230
#endif
231
  return false;
×
232
}
×
233

234
#if defined(__linux__)
235
static bool has_nvidia_driver()
185 ✔
236
{
237
  return QDir{"/proc/driver/nvidia/gpus"}
370 !
238
             .entryList(QDir::Dirs | QDir::NoDotAndDotDot)
185 !
239
             .count()
185 ✔
240
         > 0;
185 ✔
241
}
×
242

243
// Qt's QXcbEglWindow hands EGL_PLATFORM_X11_KHR a pointer to a 32-bit
244
// xcb_window_t instead of a 64-bit Window: NVIDIA's EGL rejects the window and
245
// every GL window stays black. Introduced in Qt 6.7 (12d6fc52291).
246
static constexpr bool qt_xcb_egl_window_broken()
247
{
248
#if defined(SCORE_QT_XCB_EGL_FIXED)
249
  return false;
250
#else
251
  return QT_VERSION >= QT_VERSION_CHECK(6, 7, 0);
252
#endif
253
}
254
#endif
255

256
static void setup_gpu()
124 ✔
257
{
258
#if defined(__linux__)
259
  if(has_nvidia_driver())
124 !
260
  {
261
    // libglvnd dispatches every GLX call to the vendor named here and has no
262
    // fallback, so when the kernel module and user-space driver releases differ
263
    // -- what a driver upgrade leaves until reboot -- every context creation
264
    // returns BadValue and QRhi ends up on the Null backend. Only bites GLX;
265
    // EGL does not go through libglvnd's dispatch.
266
    if(!qEnvironmentVariableIsSet("__GLX_VENDOR_LIBRARY_NAME"))
×
267
    {
268
      switch(score::nvidiaGlxVendorState())
×
269
      {
270
        case score::NvidiaGlxVendorState::Consistent:
271
        case score::NvidiaGlxVendorState::Unknown:
272
          qputenv("__GLX_VENDOR_LIBRARY_NAME", "nvidia");
×
273
          break;
×
274
        case score::NvidiaGlxVendorState::VersionMismatch:
275
          qWarning() << "score: the NVIDIA kernel module and its user-space "
×
276
                        "driver are different releases, so GLX through it "
277
                        "cannot create a context. Leaving GLX to the default "
278
                        "vendor; reboot to use the NVIDIA GPU.";
279
          break;
×
280
        case score::NvidiaGlxVendorState::NotInstalled:
281
          qWarning() << "score: an NVIDIA kernel module is loaded but no "
×
282
                        "libGLX_nvidia is installed. Leaving GLX to the "
283
                        "default vendor.";
284
          break;
×
285
        case score::NvidiaGlxVendorState::NoDriver:
286
          break;
×
287
      }
288
    }
×
289

290
    if(has_non_nvidia_gpu())
×
291
    {
292
      if(!qEnvironmentVariableIsSet("__NV_PRIME_RENDER_OFFLOAD"))
×
293
        qputenv("__NV_PRIME_RENDER_OFFLOAD", "1");
×
294
    }
×
295
  }
×
296
#endif
297
}
124 ✔
298

299
static void setup_x11(int argc, char** argv)
124 ✔
300
{
301
#if defined(__linux__)
302
  static const bool x11 = !qEnvironmentVariableIsEmpty("DISPLAY");
124 !
303
  static const bool wayland = !qEnvironmentVariableIsEmpty("WAYLAND_DISPLAY");
124 !
304
  const auto platform = qgetenv("QT_QPA_PLATFORM");
124 ✔
305
  const auto platform_in_args = std::any_of(argv, argv + argc, [](std::string_view str) {
1,024 !
306
    return str == "-platform" || str == "--platform";
900 !
307
  });
308
  const bool has_platform = !platform.isEmpty() || platform_in_args;
124 ✔
309

310
  if(!x11 && !wayland)
124 !
311
  {
312
    // Try eglfs -- unless a platform was asked for. Overwriting it here sent
313
    // QT_QPA_PLATFORM=offscreen to eglfs, which finds no display device, and
314
    // Qt then qFatal()s on the first window for having no screens. A headless
315
    // machine asking for offscreen has to get offscreen.
316
    if(!has_platform)
46 !
317
      qputenv("QT_QPA_PLATFORM", "eglfs");
×
318
    return;
46 ✔
319
  }
320
  static constexpr auto setup_x11_error_handling = [] {
61 ✔
321
    helper_dylibs.x11 = dlopen("libX11.so.6", RTLD_LAZY | RTLD_LOCAL);
61 ✔
322
    if(helper_dylibs.x11)
61 !
323
    {
324
      helper_dylibs.x11_set_error_handler = reinterpret_cast<XSetErrorHandler_ptr>(
61 ✔
325
          dlsym(helper_dylibs.x11, "XSetErrorHandler"));
61 ✔
326
      assert(helper_dylibs.x11_set_error_handler);
61 !
327

328
      if(auto sym
61 !
329
         = reinterpret_cast<int (*)()>(dlsym(helper_dylibs.x11, "XInitThreads")))
61 ✔
330
      {
331
        if(!sym())
61 !
332
        {
333
          qDebug() << "Failed to initialise xlib thread support.";
×
334
        }
×
335

336
        helper_dylibs.run_under_x11 = true;
61 ✔
337
        helper_dylibs.xwayland = wayland;
61 ✔
338

339
        // EGL is the only way to get zero-copy with dma-buf import
340
        const auto xcb_gl_integration = qgetenv("QT_XCB_GL_INTEGRATION");
61 ✔
341
        if(xcb_gl_integration.isEmpty())
61 !
342
        {
343
          if(qt_xcb_egl_window_broken() && has_nvidia_driver())
61 !
344
            qputenv("QT_XCB_GL_INTEGRATION", "xcb_glx");
×
345
          else
346
            qputenv("QT_XCB_GL_INTEGRATION", "xcb_egl");
61 !
347
        }
61 ✔
348
      }
61 ✔
349
    }
61 ✔
350
  };
61 ✔
351

352
#if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
353
  // Wayland as of Qt 6 does not seem to support QRhi properly especially on nvidia
354
  // so we still force xcb -- but only where there is an X server to force it onto.
355
  // DISPLAY says so: a Wayland session running XWayland sets it, one without does
356
  // not, and there the wayland plugin is the only one that can open a display.
357
  if(!has_platform)
78 ✔
358
  {
359
    if(x11)
61 !
360
    {
361
      qputenv("QT_QPA_PLATFORM", "xcb");
61 !
362
      setup_x11_error_handling();
61 !
363
    }
61 ✔
364
  };
61 ✔
365
#else
366
  // Only setup X11 stuff if we are going to use XCB for sure
367
  // or if we want to force running under xwayland:
368
  if(x11)
369
  {
370
    if(!wayland || platform == "xcb")
371
      setup_x11_error_handling();
372
  }
373
#endif
374
#endif
375
}
124 ✔
376

377
#if defined(__linux__)
378
extern "C" {
379
enum SuilArg
380
{
381
  SUIL_ARG_NONE
382
};
383
using suil_init_t = void (*)(int* argc, char*** argv, SuilArg key, ...);
384
}
385
#endif
386
static void setup_suil()
124 ✔
387
{
388
#if defined(__linux__)
389
  if(qEnvironmentVariableIsSet("SCORE_DISABLE_AUDIOPLUGINS"))
124 ✔
390
    return;
113 ✔
391
  if(qEnvironmentVariableIsSet("SCORE_DISABLE_LV2"))
11 !
392
    return;
×
393
  if(!helper_dylibs.run_under_x11)
11 !
394
    return;
11 ✔
395

396
  auto path = ossia::get_exe_folder();
×
397
  if(path.ends_with("/bin"))
×
398
    path.resize(path.size() - 4);
×
399

400
  // 1. In the appimage case we have to tell suil that libsuil_x11_in_qt6.so is
401
  // nrelative to the executable
402
  if(qEnvironmentVariableIsEmpty("SUIL_MODULE_DIR") && !path.empty())
×
403
  {
404
    auto suil_module_dir = path + "/lib/suil-0";
×
405
    if(QDir{}.exists(QString::fromStdString(suil_module_dir)))
×
406
    {
407
      qputenv("SUIL_MODULE_DIR", suil_module_dir.c_str());
×
408
    }
×
409
  }
×
410

411
  // 2. Init suil if necessary. We need to do this before QApplication
412
  // and thus before loading libscore_plugin_lv2.so which links to the right
413
  // libsuil-0.so...
414
  auto init_suil = [](void* self) {
×
415
    if(auto sym = reinterpret_cast<suil_init_t>(dlsym(self, "suil_init")))
×
416
    {
417
      static int argc{0};
418
      static char** argv{nullptr};
419
      sym(&argc, &argv, SUIL_ARG_NONE);
×
420
      return true;
×
421
    }
422
    return false;
×
423
  };
×
424

425
  if(auto self = dlopen(nullptr, RTLD_LAZY | RTLD_LOCAL))
×
426
  {
427
    if(init_suil(self))
×
428
      return;
×
429
  }
×
430

431
  if(QDir{}.exists(
×
432
         QString::fromStdString(path + "/src/plugins/score-plugin-lv2/libsuil-0.so.0")))
×
433
  {
434
    if(auto lib = dlopen(
×
435
           (path + "/src/plugins/score-plugin-lv2/libsuil-0.so.0").c_str(),
×
436
           RTLD_LAZY | RTLD_LOCAL))
437
    {
438
      if(init_suil(lib))
×
439
        return;
×
440
    }
×
441
  }
×
442

443
  if(auto lib = dlopen("libsuil-0.so.0", RTLD_LAZY | RTLD_LOCAL))
×
444
  {
445
    if(init_suil(lib))
×
446
      return;
×
447
  }
×
448
#endif
449
}
124 ✔
450

451
static void setup_gtk()
124 ✔
452
{
453
#if defined(__linux__)
454
  if(qEnvironmentVariableIsSet("SCORE_DISABLE_AUDIOPLUGINS"))
124 ✔
455
    return;
113 ✔
456
  if(qEnvironmentVariableIsSet("SCORE_DISABLE_LV2"))
11 !
457
    return;
×
458
  if(!helper_dylibs.run_under_x11)
11 !
459
    return;
11 ✔
460

461
  helper_dylibs.gtk2 = dlopen("libgtk-x11-2.0.so.0", RTLD_LAZY | RTLD_LOCAL);
×
462
  if(helper_dylibs.gtk2)
×
463
  {
464
    if(auto sym = reinterpret_cast<void (*)(void)>(
×
465
           dlsym(helper_dylibs.gtk2, "gtk_disable_setlocale")))
×
466
      sym();
×
467
  }
×
468
  helper_dylibs.gtk3 = dlopen("libgtk-3.so.0", RTLD_LAZY | RTLD_LOCAL);
×
469
  if(helper_dylibs.gtk3)
×
470
  {
471
    if(auto sym = reinterpret_cast<void (*)(void)>(
×
472
           dlsym(helper_dylibs.gtk3, "gtk_disable_setlocale")))
×
473
      sym();
×
474
  }
×
475
  helper_dylibs.gtk4 = dlopen("libgtk-4.so.1", RTLD_LAZY | RTLD_LOCAL);
×
476
  if(helper_dylibs.gtk4)
×
477
  {
478
    if(auto sym = reinterpret_cast<void (*)(void)>(
×
479
           dlsym(helper_dylibs.gtk4, "gtk_disable_setlocale")))
×
480
      sym();
×
481
  }
×
482
#endif
483
}
124 ✔
484

485
static void setup_gdk()
124 ✔
486
{
487
#if defined(__linux__)
488
  if(qEnvironmentVariableIsSet("SCORE_DISABLE_AUDIOPLUGINS"))
124 ✔
489
    return;
113 ✔
490
  if(qEnvironmentVariableIsSet("SCORE_DISABLE_LV2"))
11 !
491
    return;
×
492
  if(!helper_dylibs.run_under_x11)
11 !
493
    return;
11 ✔
494

495
  static bool gtk3_loaded{};
496
  dl_iterate_phdr(
×
497
      [](struct dl_phdr_info* info, size_t size, void* data) -> int {
×
498
        if(std::string_view(info->dlpi_name).find(std::string_view("qgtk3"))
×
499
           != std::string_view::npos)
×
500
          gtk3_loaded = true;
×
501
        return 0;
×
502
      },
503
      nullptr);
504

505
  if(gtk3_loaded)
×
506
    return;
×
507

508
  // Fun fact: this code has for lineage
509
  // WebKit (https://bugs.webkit.org/show_bug.cgi?id=44324) -> KDE -> maybe Netscape (?)
510
  using gdk_init_check_ptr = void* (*)(int*, char***);
511

512
  // For the handler thing: see
513
  // https://github.com/qt/qtbase/blob/dev/src/plugins/platformthemes/gtk3/qgtk3theme.cpp#L88
514
  // Basically GDK sets an error handler which exits... even though it's against the spec.
515
  X11ErrorHandler old_handler{};
×
516
  if(helper_dylibs.x11_set_error_handler)
×
517
    old_handler = helper_dylibs.x11_set_error_handler(nullptr);
×
518

519
  helper_dylibs.gdk_x11 = dlopen("libgdk-x11-2.0.so.0", RTLD_LAZY | RTLD_LOCAL);
×
520
  if(helper_dylibs.gdk_x11)
×
521
  {
522
    if(auto gdk_init_check
×
523
       = (gdk_init_check_ptr)dlsym(helper_dylibs.gdk_x11, "gdk_init_check"))
×
524
      gdk_init_check(0, 0);
×
525
  }
×
526

527
  if(helper_dylibs.x11_set_error_handler)
×
528
    helper_dylibs.x11_set_error_handler(old_handler);
×
529

530
#endif
531
}
124 ✔
532

533
struct increase_timer_precision
534
{
535
  increase_timer_precision()
124 ✔
536
  {
537
#if defined(_WIN32)
538
    // First try to set the 1ms period
539
    timeBeginPeriod(1);
540

541
    // Then maybe we can go a bit lower...
542
    ULONG currentRes{};
543
    NtSetTimerResolution(7500, TRUE, &currentRes);
544
    if(currentRes <= 8000)
545
      NtSetTimerResolution(5000, TRUE, &currentRes);
546
    if(currentRes <= 6000)
547
      NtSetTimerResolution(2500, TRUE, &currentRes);
548
    if(currentRes <= 3000)
549
      NtSetTimerResolution(1000, TRUE, &currentRes);
550
#endif
551
  }
124 ✔
552

553
  ~increase_timer_precision()
124 ✔
554
  {
555
#if defined(_WIN32)
556
    timeEndPeriod(1);
557
#endif
558
  }
124 ✔
559
};
560

561
static void setup_faust_path()
124 ✔
562
{
563
  if(!qEnvironmentVariableIsEmpty("FAUST_LIB_PATH"))
124 !
564
    return;
×
565

566
  auto path = ossia::get_exe_folder();
124 ✔
567
  if(path.empty())
124 !
568
    return;
×
569

570
#if defined(SCORE_DEPLOYMENT_BUILD)
571
#if defined(__APPLE__)
572
  path += "/../Resources/Faust";
573
#elif defined(__linux__)
574
  path += "/../share/faust";
575
#elif defined(_WIN32)
576
  path += "/faust";
577
#endif
578
#else
579
  path += "/src/plugins/score-plugin-faust/faustlibs-prefix/src/faustlibs";
124 !
580
#endif
581

582
  if(QFileInfo{QString::fromUtf8(path)}.isDir())
124 !
583
    qputenv("FAUST_LIB_PATH", path.c_str());
×
584
}
124 ✔
585

586
static void setup_opengl(bool& enable_opengl_ui)
×
587
{
588
  const auto& plat = qGuiApp->platformName();
×
589
  if(plat == "minimal" || plat == "offscreen" || plat == "vnc" || plat == "wasm")
×
590
  {
591
    return;
×
592
  }
593
  // Creates no context, so it is safe under a sanitizer -- and required there:
594
  // it runs before the SCORE_SANITIZE_SKIP_CHECKS early return below, which
595
  // would otherwise leave the default format untouched, i.e. on macOS's legacy
596
  // GL 2.1 profile, where nothing renders. Shared with the test bootstrap,
597
  // which never reaches this function at all.
598
  score::setupDefaultOpenGLFormat();
×
599

600
  if(qEnvironmentVariableIsSet("SCORE_SANITIZE_SKIP_CHECKS"))
×
601
    return;
×
602

603
#ifndef QT_NO_OPENGL
604
#if (defined(__arm__) || defined(__aarch64__)) && !defined(_WIN32) && !defined(__APPLE__)
605
  // Raspberry Pi & such: handled by setupDefaultOpenGLFormat() above.
606
#elif defined(__APPLE__)
607
  // Handled by setupDefaultOpenGLFormat() above.
608
#else
609
  {
610
    // Desktop GL
611
    std::vector<std::pair<int, int>> versions_to_test
612
        = {{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0},
×
613
           {3, 3}, {3, 2}, {3, 1}, {3, 0}, {2, 1}, {2, 0}};
×
614

615
    QOffscreenSurface surf;
×
616
    surf.create();
×
617
    {
618
      QOpenGLContext ctx;
×
619
      if(!ctx.create())
×
620
      {
621
        qDebug() << "OpenGL detection skipped, cannot create any OpenGL context";
×
622
        enable_opengl_ui = false;
×
623
        return;
×
624
      }
625
      if(!ctx.makeCurrent(&surf))
×
626
      {
627
        qDebug() << "OpenGL detection skipped, cannot make an offscreen surface "
×
628
                    "current";
629
        enable_opengl_ui = false;
×
630
        return;
×
631
      }
632

633
      ctx.functions()->initializeOpenGLFunctions();
×
634

635
      if(auto gl_renderer = (const char*)ctx.functions()->glGetString(GL_RENDERER))
×
636
      {
637
        if(auto ver = QString::fromUtf8(gl_renderer);
×
638
           ver.contains("llvmpipe", Qt::CaseInsensitive))
×
639
        {
640
          qDebug() << "LLVMPIPE detected, not changing the default format as it crashes";
×
641
          enable_opengl_ui = false;
×
642
          return;
×
643
        }
644
      }
×
645
    }
×
646

647
    QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
×
648
    fmt.setProfile(QSurfaceFormat::CoreProfile);
×
649
    fmt.setRenderableType(QSurfaceFormat::OpenGL);
×
650
    fmt.setSwapInterval(1);
×
651
    fmt.setStencilBufferSize(8);
×
652
    bool ok = false;
×
653
    for(auto [maj, min] : versions_to_test)
×
654
    {
655
      fmt.setMajorVersion(maj);
×
656
      fmt.setMinorVersion(min);
×
657

658
      QOpenGLContext ctx;
×
659
      ctx.setFormat(fmt);
×
660
      if(ctx.create())
×
661
      {
662
        if(ctx.makeCurrent(&surf))
×
663
        {
664
          qDebug().nospace() << "Using highest available OpenGL version: "
×
665
                             << ctx.format().majorVersion() << "."
×
666
                             << ctx.format().minorVersion();
×
667
          if(maj < 3 || (maj == 3 && min < 2))
×
668
            qDebug() << "Warning ! This OpenGL version is too old for every feature to "
×
669
                        "work correctly. Consider updating your graphics card.";
670

671
          if(maj < 2)
×
672
            // GL 1: we don't even try
673
            ok = false;
×
674
          else
675
            // GL 2: we try
676
            ok = true;
×
677
          break;
×
678
        }
679
      }
×
680
    }
×
681
    if(!ok)
×
682
    {
683
      qDebug() << "OpenGL minimum version not supported";
×
684
      enable_opengl_ui = false;
×
685
    }
×
686
    else
687
    {
688
      fmt.setDefaultFormat(fmt);
×
689
    }
690
  }
×
691
#endif
692
#endif
693
  return;
×
694
}
×
695

696
static void setup_locale()
124 ✔
697
{
698
  QLocale::setDefault(QLocale::C);
124 !
699
  setlocale(LC_ALL, "C");
124 ✔
700
}
124 ✔
701

702
static void setup_app_flags()
124 ✔
703
{
704
  qputenv("ORT_DISABLE_TELEMETRY", "1");
124 ✔
705
  qputenv("QSG_USE_SIMPLE_ANIMATION_DRIVER", "1");
124 ✔
706
  qputenv("QSG_RENDER_LOOP", "basic");
124 ✔
707
  qputenv("QT3D_RENDERER", "rhi");
124 ✔
708
  // Consistency in looks across macOS, Windows (which prevents the horrible 125% scaling) and Linux
709
  // FIXME in Qt 6 this is entirely broken... https://bugreports.qt.io/browse/QTBUG-103225
710
  // qputenv("QT_FONT_DPI", "96");
711

712
  if(!qEnvironmentVariableIsSet("QT_SUBPIXEL_AA_TYPE"))
124 !
713
    qputenv("QT_SUBPIXEL_AA_TYPE", "RGB");
124 ✔
714

715
  // Really makes monospace HintSlight fonts look better
716
  if(!qEnvironmentVariableIsSet("FREETYPE_PROPERTIES"))
124 !
717
    qputenv("FREETYPE_PROPERTIES", "cff:no-stem-darkening=0 autofitter:no-stem-darkening=0 type1:no-stem-darkening=0 t1cid:no-stem-darkening=0");
124 ✔
718

719
#if defined(__APPLE__)
720
  // Same rasteriser as everywhere else: CoreText ignores
721
  // QFont::HintingPreference. Packaged builds get this from qt.conf already.
722
  if(!qEnvironmentVariableIsSet("QT_QPA_PLATFORM"))
723
    qputenv("QT_QPA_PLATFORM", "cocoa:fontengine=freetype");
724
#endif
725

726
#if defined(__EMSCRIPTEN__)
727
  qRegisterMetaType<Qt::ApplicationState>();
728
  qRegisterMetaType<QItemSelection>();
729
  QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets, true);
730
#endif
731

732
#if !defined(__EMSCRIPTEN__)
733
  QCoreApplication::setAttribute(Qt::AA_CompressHighFrequencyEvents, true);
124 ✔
734
#endif
735

736
  QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false);
124 ✔
737
#if defined(__linux__)
738
  // Else things look horrible on KDE plasma, etc
739
  qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
124 ✔
740
  // qputenv("QT_NO_GLIB", "1"); // looks like it actually prevents the app from starting on GNOME
741

742
  if(!qEnvironmentVariableIsSet("FLATPAK_ID"))
124 !
743
  {
744
    // https://github.com/ossia/score/issues/953
745
    // https://github.com/ossia/score/issues/1046
746
    // https://github.com/ossia/score/issues/1725 for the flatpak reenablement
747
    QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs, true);
124 ✔
748
  }
124 ✔
749
#if !defined(__x86_64__)
750
  QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, false);
751
#endif
752
#endif
753

754
  if(qEnvironmentVariableIsSet("SCORE_FORCE_NATIVE_FILE_DIALOGS"))
124 !
755
  {
756
    QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs, false);
×
757
  }
×
758
}
124 ✔
759

760
#if FFTW_HAS_THREADS
761
#include <fftw3.h>
762
static void setup_fftw()
124 ✔
763
{
764
  // See http://fftw.org/fftw3_doc/Thread-safety.html
765
#if defined(OSSIA_FFTW_SINGLE_ONLY)
766
  fftwf_make_planner_thread_safe();
767
  fftwf_plan_with_nthreads(1);
768
  fftwf_init_threads();
769
#else
770
  fftw_make_planner_thread_safe();
124 ✔
771
  fftw_plan_with_nthreads(1);
124 ✔
772
  fftw_init_threads();
124 ✔
773
#endif
774
}
124 ✔
775
#else
776
static void setup_fftw() { }
777
#endif
778

779
// tty functions needed because when exiting with
780
// eglfs and vkkhrdisplay we cannot use the keyboard anymore
781
// https://stackoverflow.com/a/66526943
782
#if defined(KDSKBMODE)
783
static int linux_tty_k_mode = -1;
784
static void read_linux_tty()
124 ✔
785
{
786
  int tfd = open("/dev/tty", O_RDWR);
124 ✔
787
  if(tfd == -1)
124 !
788
    return;
124 ✔
789
  ioctl(tfd, KDGKBMODE, &linux_tty_k_mode);
×
790
  close(tfd);
×
791
}
124 ✔
792
static void restore_linux_tty()
×
793
{
794
  int tfd = open("/dev/tty", O_RDWR);
×
795
  if(tfd == -1)
×
796
    return;
×
797
  ioctl(tfd, KDSETMODE, KD_TEXT);          // return to text mode from graphics mode
×
798
  ioctl(tfd, 0x4b51, 0);                   // 0x4b51=KDKBMUTE, from qfbvthandler.cpp
×
799
  ioctl(tfd, KDSKBMODE, linux_tty_k_mode); // set keyboard mode back
×
800
  linux_tty_k_mode = -1;
×
801
  const auto blink_on = "\033[9;15]\033[?33h\033[?25h\033[?0c"; // from qfbvthandler.cpp
×
802
  write(tfd, blink_on, strlen(blink_on) + 1); // enable blanking and cursor
×
803
  close(tfd);
×
804
}
×
805
#endif
806

807
#if defined(_WIN32)
808
// Taskbar identity of a custom app (tools/launcher/launcher.cpp passes it in the environment).
809
// https://learn.microsoft.com/en-us/windows/win32/shell/appids
810
namespace
811
{
812
struct
813
{
814
  std::wstring id;
815
  std::wstring relaunch_command;
816
  std::wstring relaunch_name;
817
  std::wstring relaunch_icon;
818
} windows_app_identity;
819

820
static std::wstring windows_env(const wchar_t* var)
821
{
822
  // Read with the Win32 API: nothing in score writes these, and Qt is not up yet
823
  std::wstring s(GetEnvironmentVariableW(var, nullptr, 0), L'\0');
824
  if(!s.empty())
825
    s.resize(GetEnvironmentVariableW(var, s.data(), DWORD(s.size())));
826
  return s;
827
}
828

829
// PKEY_AppUserModel_* (propkey.h), spelled out so no GUID library is needed
830
static PROPERTYKEY app_user_model_key(DWORD pid)
831
{
832
  return {{0x9F4C2855, 0x9F79, 0x4B39, {0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3}}, pid};
833
}
834

835
static void set_window_app_identity(HWND hwnd, bool set)
836
{
837
  IPropertyStore* store{};
838
  if(FAILED(SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&store))))
839
    return;
840
  // VT_EMPTY removes a property: they must all be removed before the window is destroyed
841
  auto put = [&](DWORD pid, const std::wstring& v) {
842
    PROPVARIANT pv{};
843
    if(set && !v.empty())
844
    {
845
      pv.vt = VT_LPWSTR;
846
      pv.pwszVal = const_cast<wchar_t*>(v.c_str());
847
    }
848
    store->SetValue(app_user_model_key(pid), pv);
849
  };
850
  // Relaunch properties first: setting the ID is what notifies the taskbar
851
  put(2, windows_app_identity.relaunch_command); // RelaunchCommand
852
  put(4, windows_app_identity.relaunch_name);    // RelaunchDisplayNameResource
853
  put(3, windows_app_identity.relaunch_icon);    // RelaunchIconResource
854
  put(5, windows_app_identity.id);               // ID
855
  store->Release();
856
}
857

858
// Labels every top-level window when its HWND is created, and clears it before it goes
859
class WindowsAppIdentityFilter final : public QObject
860
{
861
public:
862
  using QObject::QObject;
863
  bool eventFilter(QObject* obj, QEvent* ev) override
864
  {
865
    if(ev->type() != QEvent::PlatformSurface)
866
      return false;
867
    auto w = qobject_cast<QWindow*>(obj);
868
    if(!w || !w->handle() || !w->isTopLevel())
869
      return false;
870
    if(w->type() != Qt::Window && w->type() != Qt::Dialog)
871
      return false;
872
    const auto t = static_cast<QPlatformSurfaceEvent*>(ev)->surfaceEventType();
873
    set_window_app_identity(
874
        reinterpret_cast<HWND>(w->winId()), t == QPlatformSurfaceEvent::SurfaceCreated);
875
    return false;
876
  }
877
};
878
}
879
#endif
880

881
// Must run before any window exists; without SCORE_CUSTOM_APP_USER_MODEL_ID nothing changes
882
static void setup_windows_app_identity()
124 ✔
883
{
884
#if defined(_WIN32)
885
  auto& ident = windows_app_identity;
886
  ident.id = windows_env(L"SCORE_CUSTOM_APP_USER_MODEL_ID");
887
  if(ident.id.empty())
888
    return;
889
  SetCurrentProcessExplicitAppUserModelID(ident.id.c_str());
890

891
  // Pinning the running window pins the launcher, which sets up the environment, not app-bin.exe
892
  if(auto launcher = windows_env(L"SCORE_CUSTOM_APP_LAUNCHER"); !launcher.empty())
893
  {
894
    ident.relaunch_command = L"\"" + launcher + L"\"";
895
    ident.relaunch_icon = launcher + L",0";
896
    ident.relaunch_name = windows_env(L"SCORE_CUSTOM_APP_APPLICATION_NAME");
897
    if(ident.relaunch_name.empty())
898
      ident.relaunch_name = ident.id;
899
  }
900
#endif
901
}
124 ✔
902

903
static void install_windows_app_identity_filter()
124 ✔
904
{
905
#if defined(_WIN32)
906
  if(!windows_app_identity.id.empty())
907
    qApp->installEventFilter(new WindowsAppIdentityFilter{qApp});
908
#endif
909
}
124 ✔
910

911
static void setup_priority()
124 ✔
912
{
913
#if defined(_WIN32)
914
  SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
915
#endif
916
}
124 ✔
917

918
static void setup_limits()
124 ✔
919
{
920
#if HAS_RLIMIT
921
  constexpr int min_fds = 10000;
124 ✔
922
  struct rlimit rlim;
923
  if(getrlimit(RLIMIT_NOFILE, &rlim) != 0)
124 !
924
    return;
×
925

926
  if(rlim.rlim_cur != RLIM_INFINITY && rlim.rlim_cur < rlim_t(min_fds))
124 !
927
  {
928
    if(rlim.rlim_max == RLIM_INFINITY)
×
929
      rlim.rlim_cur = min_fds;
×
930
    else if(rlim.rlim_cur == rlim.rlim_max)
×
931
      return;
×
932
    else
933
      rlim.rlim_cur = rlim.rlim_max;
×
934

935
    setrlimit(RLIMIT_NOFILE, &rlim);
×
936
  }
×
937
#endif
938
}
124 ✔
939

940
namespace
941
{
942
static void setup_qml()
124 ✔
943
{
944
#if defined(__SANITIZE_ADDRESS__)
945
  if(!qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER"))
946
    qputenv("QV4_FORCE_INTERPRETER", "1");
947
  if(!qEnvironmentVariableIsSet("QV4_MM_AGGRESSIVE_GC"))
948
    qputenv("QV4_MM_AGGRESSIVE_GC", "1");
949
#endif
950
  if(!qEnvironmentVariableIsSet("QV4_JS_MAX_STACK_SIZE"))
124 !
951
    qputenv("QV4_JS_MAX_STACK_SIZE", "16777216");
124 ✔
952
  if(!qEnvironmentVariableIsSet("QV4_GC_MAX_STACK_SIZE"))
124 !
953
    qputenv("QV4_GC_MAX_STACK_SIZE", "16777216");
124 ✔
954
  if(!qEnvironmentVariableIsSet("QML_XHR_ALLOW_FILE_READ"))
124 !
955
    qputenv("QML_XHR_ALLOW_FILE_READ", "1");
124 ✔
956
  if(!qEnvironmentVariableIsSet("QML_XHR_ALLOW_FILE_WRITE"))
124 !
957
    qputenv("QML_XHR_ALLOW_FILE_WRITE", "1");
124 ✔
958
}
124 ✔
959

960
struct failsafe
961
{
962
  // An explicit way out, for automated runs. The bit is deliberately sticky --
963
  // clear() below refuses to remove it when this process itself started in
964
  // failsafe, so a genuinely crashing install stays safe across restarts. The
965
  // cost is that one crashed startup degrades every later launch (opengl forced
966
  // off, see the use at the bottom of main) until the file is deleted by hand,
967
  // which in a test sweep turns the rest of the run into failsafe-mode results.
968
  // Spelled like the neighbouring SCORE_DISABLE_AUDIOPLUGINS / SCORE_DISABLE_LV2.
969
  //
970
  // When set, failsafe is bypassed entirely: not read, not written, not
971
  // cleared. Any existing bit is left alone rather than deleted, so this does
972
  // not quietly discard state the user may want.
973
  const bool disabled = qEnvironmentVariableIsSet("SCORE_DISABLE_FAILSAFE");
124 ✔
974
  const bool fs = !disabled && this->read();
124 !
975

976
  // Set once, when we arm the bit, and read back by the atexit handler below.
977
  // A plain std::string and ::remove rather than QString/QFile: this runs
978
  // during exit, when Qt may be past the point of being usable.
979
  static inline std::string armed_path{};
980

981
  // ::exit() does not run main()'s local destructors, so the failsafe object's
982
  // own scope guarantees nothing -- but it does run atexit handlers. Without
983
  // this handler the bit survives a --help or --version run: QCommandLineParser's
984
  // showHelp() calls ::exit(0) from inside the Application constructor, above
985
  // failsafe.clear() in main(), leaving the bit armed so the next real launch
986
  // starts degraded with opengl forced off.
987
  static void clear_at_exit() noexcept
124 ✔
988
  {
989
    if(!armed_path.empty())
124 !
990
    {
991
      ::remove(armed_path.c_str());
×
992
      armed_path.clear();
×
993
    }
×
994
  }
124 ✔
995

996
  explicit failsafe()
124 ✔
997
  {
998
    if(disabled)
124 !
999
      return;
×
1000

1001
    if(!fs)
124 !
1002
    {
1003
      this->write();
124 ✔
1004
      armed_path = this->path().toStdString();
124 !
1005
      std::atexit(&failsafe::clear_at_exit);
124 ✔
1006
    }
124 ✔
1007
    else
1008
    {
1009
      fprintf(stderr, "ossia score: starting in failsafe mode\n");
×
1010
      fflush(stderr);
×
1011
    }
1012
  }
124 ✔
1013

1014
  QString path()
496 ✔
1015
  {
1016
    auto conf = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
496 ✔
1017
    return conf + QDir::separator() + "ossia" + QDir::separator() + "failsafe.bit";
496 !
1018
  }
496 ✔
1019

1020
  bool read() { return QFile::exists(this->path()); }
124 !
1021

1022
  void write()
124 ✔
1023
  {
1024
    QFile f{this->path()};
124 !
1025
    if(f.open(QIODevice::WriteOnly))
124 !
1026
      f.write("1");
122 !
1027
  }
124 ✔
1028

1029
  void clear()
124 ✔
1030
  {
1031
    if(disabled)
124 !
1032
      return;
×
1033

1034
    // We only clear the failsafe if it was not set otherwise
1035
    // it would crash every other time..
1036
    if(!fs)
124 !
1037
    {
1038
      QFile f{this->path()};
124 !
1039
      f.remove();
124 !
1040
      // Nothing left for the atexit handler to do; also stops it touching the
1041
      // path again after a later launch may have legitimately re-armed it.
1042
      armed_path.clear();
124 ✔
1043
    }
124 ✔
1044
  }
124 ✔
1045

1046
  operator bool() const noexcept { return fs; }
124 ✔
1047
};
1048
}
1049

1050
int main(int argc, char** argv)
124 ✔
1051
{
1052
#if defined(_WIN32)
1053
#if defined(SCORE_HAS_CPP_WINRT)
1054
  winrt::uninit_apartment();
1055
  winrt::init_apartment(winrt::apartment_type::single_threaded);
1056
#else
1057
  score::compat::uninit_apartment();
1058
  score::compat::init_apartment_sta();
1059
#endif
1060
#endif
1061

1062
  setup_windows_app_identity();
124 ✔
1063

1064
  struct failsafe failsafe;
124 ✔
1065

1066
#if defined(__APPLE__)
1067
  disableAppRestore();
1068
  disableAppNap();
1069
  ensureDyldPath();
1070
  // FIXME broken in qt6 qputenv("QT_MAC_WANTS_LAYER", "1");
1071
#endif
1072

1073
#if defined(KDSKBMODE)
1074
  read_linux_tty();
124 ✔
1075
#endif
1076

1077
  setup_priority();
124 ✔
1078
  setup_limits();
124 ✔
1079
  setup_gpu();
124 ✔
1080
  setup_x11(argc, argv);
124 ✔
1081
  setup_gtk();
124 ✔
1082
  setup_suil();
124 ✔
1083
  setup_faust_path();
124 ✔
1084
  setup_locale();
124 ✔
1085
  setup_app_flags();
124 ✔
1086
  setup_fftw();
124 ✔
1087
  setup_qml();
124 ✔
1088

1089
  QPixmapCache::setCacheLimit(819200);
124 ✔
1090
#if QT_WEBVIEW_LIB
1091
  QtWebView::initialize();
1092
#endif
1093
  Application app(argc, argv);
124 ✔
1094
  install_windows_app_identity_filter();
124 !
1095

1096
#if defined(_WIN32)
1097
#if defined(SCORE_HAS_CPP_WINRT)
1098
  winrt::uninit_apartment();
1099
  winrt::init_apartment(winrt::apartment_type::single_threaded);
1100
#else
1101
  score::compat::uninit_apartment();
1102
  score::compat::init_apartment_sta();
1103
#endif
1104
#endif
1105

1106
#if defined(KDSKBMODE)
1107
  {
1108
    const auto& plat = QGuiApplication::platformName();
124 !
1109
    const bool linux_tty_needs_restore = plat == "eglfs" || plat == "vkkhrdisplay";
124 !
1110
    if(linux_tty_needs_restore)
124 !
1111
      qAddPostRoutine([] { restore_linux_tty(); });
×
1112
  }
124 ✔
1113
#endif
1114

1115
  setup_gdk();
124 !
1116

1117
#if defined(__APPLE__)
1118
  disableAppNap();
1119
#endif
1120

1121
#if defined(__EMSCRIPTEN__)
1122
  app.appSettings.opengl = false;
1123
#endif
1124

1125
  if(failsafe)
124 !
1126
    app.appSettings.opengl = false;
×
1127

1128
#if defined(__linux__) && !(defined(__arm__) || defined(__aarch64__))
1129
  // On linux under offscreen, etc it crashes inside
1130
  // QOffscreenSurface::create
1131
  // so we check if we set --no-opengl explicitly
1132
  if(app.appSettings.opengl)
124 !
1133
#endif
1134
    setup_opengl(app.appSettings.opengl);
×
1135

1136
  failsafe.clear();
124 !
1137
  QTimer::singleShot(1, &app, &Application::init);
124 !
1138

1139
  increase_timer_precision timerRes;
124 !
1140

1141
#if __has_include(<valgrind/callgrind.h>)
1142
  /*
1143
  QTimer::singleShot(5000, [] {
1144
    score::information(nullptr, "debug start", "debug start");
1145
    CALLGRIND_START_INSTRUMENTATION;
1146
    QTimer::singleShot(10000, [] {
1147
      CALLGRIND_STOP_INSTRUMENTATION;
1148
      CALLGRIND_DUMP_STATS;
1149
      score::information(nullptr, "debug stop", "debug stop");
1150
    });
1151
  });*/
1152
#endif
1153

1154
  ossia::disable_fpe();
124 !
1155
  int res = app.exec();
124 !
1156

1157
  return res;
124 ✔
1158
}
124 ✔
1159

1160
#if defined(Q_CC_MSVC)
1161
#include <qt_windows.h>
1162

1163
#include <ShlObj.h>
1164
#include <shellapi.h>
1165
#include <stdio.h>
1166
#include <windows.h>
1167
static inline char* wideToMulti(int codePage, const wchar_t* aw)
1168
{
1169
  const int required = WideCharToMultiByte(codePage, 0, aw, -1, NULL, 0, NULL, NULL);
1170
  char* result = new char[required];
1171
  WideCharToMultiByte(codePage, 0, aw, -1, result, required, NULL, NULL);
1172
  return result;
1173
}
1174

1175
extern "C" int APIENTRY
1176
WinMain(HINSTANCE, HINSTANCE, LPSTR /*cmdParamarg*/, int /* cmdShow */)
1177
{
1178
  int argc;
1179
  wchar_t** argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
1180
  if(!argvW)
1181
    return -1;
1182
  char** argv = new char*[argc + 1];
1183
  for(int i = 0; i < argc; ++i)
1184
    argv[i] = wideToMulti(CP_ACP, argvW[i]);
1185
  argv[argc] = nullptr;
1186
  LocalFree(argvW);
1187
  const int exitCode = main(argc, argv);
1188
  for(int i = 0; i < argc && argv[i]; ++i)
1189
    delete[] argv[i];
1190
  delete[] argv;
1191
  return exitCode;
1192
}
1193

1194
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc