mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[glass] Configure delay loading for windows camera server support (#3803)
We don't currently support cameras in glass, but it's something we want to do in the future. However, when we do this, glass will completely stop working on N builds of windows, and it would fail to load at all with no messages. To solve this, we can delayload the media foundation dlls that are missing. The executable will then launch even without the dlls present, and we can attempt to load them at runtime and dynamically disable camera support. When we get around to implementing it, we can just call HasCameraSupport, and dynamically hide all camera related code behind that flag.
This commit is contained in:
@@ -185,15 +185,18 @@ if (!project.hasProperty('onlylinuxathena') && !project.hasProperty('onlylinuxra
|
||||
it.buildable = false
|
||||
return
|
||||
}
|
||||
lib project: ':cscore', library: 'cscore', linkage: 'static'
|
||||
lib library: 'glassnt', linkage: 'static'
|
||||
lib library: nativeName, linkage: 'static'
|
||||
lib project: ':ntcore', library: 'ntcore', linkage: 'static'
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
|
||||
lib project: ':wpimath', library: 'wpimath', linkage: 'static'
|
||||
lib project: ':wpigui', library: 'wpigui', linkage: 'static'
|
||||
nativeUtils.useRequiredLibrary(it, 'opencv_static')
|
||||
nativeUtils.useRequiredLibrary(it, 'imgui_static')
|
||||
if (it.targetPlatform.operatingSystem.isWindows()) {
|
||||
it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib'
|
||||
it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind'
|
||||
} else if (it.targetPlatform.operatingSystem.isMacOsX()) {
|
||||
it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore'
|
||||
} else {
|
||||
|
||||
52
glass/src/app/native/cpp/camerasupport.cpp
Normal file
52
glass/src/app/native/cpp/camerasupport.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "camerasupport.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Windows.h"
|
||||
#include "delayimp.h"
|
||||
#pragma comment(lib, "delayimp.lib")
|
||||
static int CheckDelayException(int exception_value) {
|
||||
if (exception_value ==
|
||||
VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND) ||
|
||||
exception_value ==
|
||||
VcppException(ERROR_SEVERITY_ERROR, ERROR_PROC_NOT_FOUND)) {
|
||||
// This example just executes the handler.
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
// Don't attempt to handle other errors
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
static bool TryDelayLoadAllImports(LPCSTR szDll) {
|
||||
__try {
|
||||
HRESULT hr = __HrLoadAllImportsForDll(szDll);
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
} __except (CheckDelayException(GetExceptionCode())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
namespace glass {
|
||||
bool HasCameraSupport() {
|
||||
bool hasCameraSupport = false;
|
||||
hasCameraSupport = TryDelayLoadAllImports("MF.dll");
|
||||
if (hasCameraSupport) {
|
||||
hasCameraSupport = TryDelayLoadAllImports("MFPlat.dll");
|
||||
}
|
||||
if (hasCameraSupport) {
|
||||
hasCameraSupport = TryDelayLoadAllImports("MFReadWrite.dll");
|
||||
}
|
||||
return hasCameraSupport;
|
||||
}
|
||||
} // namespace glass
|
||||
#else
|
||||
namespace glass {
|
||||
bool HasCameraSupport() {
|
||||
return true;
|
||||
}
|
||||
} // namespace glass
|
||||
#endif
|
||||
9
glass/src/app/native/cpp/camerasupport.h
Normal file
9
glass/src/app/native/cpp/camerasupport.h
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace glass {
|
||||
bool HasCameraSupport();
|
||||
} // namespace glass
|
||||
Reference in New Issue
Block a user