Skip to content

Add error logging to GLFW and Flutter setup #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion example/linux_fde/flutter_embedder_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ std::string GetExecutableDirectory() {

int main(int argc, char **argv) {
if (!flutter_desktop_embedding::FlutterInit()) {
std::cerr << "Couldn't init GLFW" << std::endl;
std::cerr << "Unable to init GLFW; exiting." << std::endl;
return EXIT_FAILURE;
}

// Resources are located relative to the executable.
Expand All @@ -76,6 +77,7 @@ int main(int argc, char **argv) {
640, 480, assets_path, icu_data_path, arguments);
if (window == nullptr) {
flutter_desktop_embedding::FlutterTerminate();
std::cerr << "Unable to create Flutter window; exiting." << std::endl;
return EXIT_FAILURE;
}

Expand Down
4 changes: 3 additions & 1 deletion example/windows_fde/flutter_embedder_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

int main(int argc, char **argv) {
if (!flutter_desktop_embedding::FlutterInit()) {
std::cout << "Couldn't init GLFW" << std::endl;
std::cerr << "Unable to init GLFW; exiting." << std::endl;
return EXIT_FAILURE;
}
// Arguments for the Flutter Engine.
std::vector<std::string> arguments;
Expand All @@ -33,6 +34,7 @@ int main(int argc, char **argv) {
"..\\..\\library\\windows\\dependencies\\engine\\icudtl.dat", arguments);
if (window == nullptr) {
flutter_desktop_embedding::FlutterTerminate();
std::cerr << "Unable to create Flutter window; exiting." << std::endl;
return EXIT_FAILURE;
}

Expand Down
14 changes: 11 additions & 3 deletions library/common/glfw/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ static void *GLFWProcResolver(void *user_data, const char *name) {
return reinterpret_cast<void *>(glfwGetProcAddress(name));
}

static void GLFWErrorCallback(int error_code, const char *description) {
std::cerr << "GLFW error " << error_code << ": " << description << std::endl;
}

// Spins up an instance of the Flutter Engine.
//
// This function launches the Flutter Engine in a background thread, supplying
Expand Down Expand Up @@ -276,17 +280,21 @@ static FlutterEngine RunFlutterEngine(
auto result =
FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, window, &engine);
if (result != kSuccess || engine == nullptr) {
std::cerr << "Failed to start Flutter engine: error " << result
<< std::endl;
return nullptr;
}
return engine;
}

namespace flutter_desktop_embedding {

// Initialize glfw
bool FlutterInit() { return glfwInit(); }
bool FlutterInit() {
// Before making any GLFW calls, set up a logging error handler.
glfwSetErrorCallback(GLFWErrorCallback);
return glfwInit();
}

// Tear down glfw
void FlutterTerminate() { glfwTerminate(); }

PluginRegistrar *GetRegistrarForPlugin(GLFWwindow *flutter_window,
Expand Down
10 changes: 7 additions & 3 deletions library/macos/FLEViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,14 @@ - (BOOL)launchEngineInternalWithAssetsPath:(NSURL *)assets
flutterArguments.command_line_argv = argv;
flutterArguments.platform_message_callback = (FlutterPlatformMessageCallback)OnPlatformMessage;

BOOL result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &flutterArguments,
(__bridge void *)(self), &_engine) == kSuccess;
FlutterResult result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &flutterArguments,
(__bridge void *)(self), &_engine);
free(argv);
return result;
if (result != kSuccess) {
NSLog(@"Failed to start Flutter engine: error %d", result);
return NO;
}
return YES;
}

+ (FlutterRendererConfig)createRenderConfigHeadless:(BOOL)headless {
Expand Down