From 53e52cf3a8dfd2d28b10da1685037c9f65c6fc99 Mon Sep 17 00:00:00 2001 From: Michael Haberler Date: Fri, 10 Nov 2023 09:17:14 +0100 Subject: [PATCH] make the CMake_WASM example work again --- examples_for_PC/CMake_WASM/CMakeLists.txt | 2 +- examples_for_PC/CMake_WASM/LGFX_WASM.cpp | 9 ++++----- examples_for_PC/CMake_WASM/README.md | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/examples_for_PC/CMake_WASM/CMakeLists.txt b/examples_for_PC/CMake_WASM/CMakeLists.txt index c189b433..702a9991 100644 --- a/examples_for_PC/CMake_WASM/CMakeLists.txt +++ b/examples_for_PC/CMake_WASM/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12) project (lv_wasm) add_definitions(-DLGFX_SDL) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -s USE_SDL=2") +set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -g -s USE_SDL=2") include_directories(../../../LovyanGFX/src/) diff --git a/examples_for_PC/CMake_WASM/LGFX_WASM.cpp b/examples_for_PC/CMake_WASM/LGFX_WASM.cpp index ed6c041a..804a9307 100644 --- a/examples_for_PC/CMake_WASM/LGFX_WASM.cpp +++ b/examples_for_PC/CMake_WASM/LGFX_WASM.cpp @@ -6,16 +6,15 @@ void setup(void); void loop(void); -void loopThread(void *arg) +void loopThread(void) { + lgfx::Panel_sdl::loop(); loop(); - lgfx::Panel_sdl::sdl_event_handler(); } -int monitor_hor_res, monitor_ver_res; - int main(int argc, char **argv) { setup(); - emscripten_set_main_loop_arg(loopThread, NULL, -1, true); + lgfx::Panel_sdl::setup(); + emscripten_set_main_loop(loopThread, -1, true); } diff --git a/examples_for_PC/CMake_WASM/README.md b/examples_for_PC/CMake_WASM/README.md index 7826996d..4386f8c3 100644 --- a/examples_for_PC/CMake_WASM/README.md +++ b/examples_for_PC/CMake_WASM/README.md @@ -14,4 +14,19 @@ 2. `cd build` 3. `emcmake cmake ..` 4. `emmake make` +5. `http-server` 5. open `index.html` in your browser. + +## Notes +this is a debug build: `set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -g -s USE_SDL=2")` +It uses the SDL2 library bundled with the Emscripten SDK so I think the `Install SDL`` +is not necessary + +### Debugging +I followed the [Debugging WebAssembly with modern tools](https://developer.chrome.com/blog/wasm-debugging-2020/) tutorial and was able to debug at the C source level just fine + + +Steps: +1. Install Chrome Canary +2. Install the C/C++ DevTools Support (DWARF) as outline +3. serve `index.html` via `http-server` - opening file//wherever/index.html breaks debugging