Skip to content
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

refactor(native): use wrapped pointers #992

Merged
merged 15 commits into from
Nov 24, 2020
Merged

Conversation

zbaylin
Copy link
Member

@zbaylin zbaylin commented Aug 25, 2020

This is currently breaking very early on -- I get a segfault with the Window in SDL2 and I can't seem to figure out why.

Here's a stack trace from LLDB:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1400)
  * frame #0: 0x00000001000a2d2d Examples`SDL_GetWindowID_REAL(window=0x0000000000001400) at SDL_video.c:1719:5 [opt]
    frame #1: 0x0000000100b0a325 Examples`resdl_SDL_GetWindowId(vWindow=4432065872) at sdl2_wrapper.cpp:1539:18
    frame #2: 0x00000001002707f0 Examples`camlRevery_Core__Window__create_1627   768
    frame #3: 0x0000000100273656 Examples`camlRevery_Core__App__createWindow_inner_1628   22
    frame #4: 0x00000001000f02a1 Examples`camlExamples__init_1444   1361
    frame #5: 0x000000010027386c Examples`camlRevery_Core__App__start_951   284
    frame #6: 0x0000000100b599b8 Examples`caml_start_program   72

If anybody has any ideas, let me know! I'll keep looking at it.

@zbaylin zbaylin requested a review from bryphe August 25, 2020 00:31
@zbaylin zbaylin added the WIP label Aug 25, 2020
@bryphe
Copy link
Member

bryphe commented Aug 25, 2020

Thanks for the help with this, Zach! Much appreciated

@zbaylin
Copy link
Member Author

zbaylin commented Aug 25, 2020

@bryphe -- I think I implemented all the fixes I caught (including the ones you mentioned), but I'm still getting a segfault on GL_Setup, which is called right after window creation.

@zbaylin
Copy link
Member Author

zbaylin commented Sep 9, 2020

@bryphe after our conversation last night I realized that was probably why I couldn't get this PR working. I changed the wrap and unwrap functions and, lo and behold, it works! Let me know if there is anything else you need me to do!

@zbaylin zbaylin requested a review from bryphe October 13, 2020 18:26
@zbaylin zbaylin removed the WIP label Oct 13, 2020
Copy link
Member

@bryphe bryphe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code change looks great, @zbaylin - thanks for the heroic work here. One step closer to multicore... 😎

We should validate it across platforms - a sanity check running the example app Onivim 2 against this PR should be sufficient. There's some C bindings that aren't covered in our tests yet, so I just want to make sure we test those:

  • Windows - Example App
  • Windows - Onivim 2
  • OSX - Example App
  • OSX - Onivim 2
  • Linux - Example App
  • Linux - Onivim 2

@bryphe
Copy link
Member

bryphe commented Oct 15, 2020

OSX looks good! Wasn't sure if you already tested on Windows / Linux - let me know if I can help validate either of those platforms

@zbaylin
Copy link
Member Author

zbaylin commented Oct 16, 2020

@bryphe I just tested Linux with both the example app and Oni2, and both work! @CrossR mentioned that he might be able to help test on Windows as well

@CrossR
Copy link
Member

CrossR commented Oct 16, 2020

The Icon Features bit (progress displayed on the Icon) example crashes for me on Windows with:

Fatal error: exception Invalid_argument("compare: abstract value")
Raised by primitive operation at file "examples/NativeIconExample.re", line 23, characters 11-15
Called from file "lib/Hooks.re", line 235, characters 11-70
Called from file "lib/Hooks.re", line 307, characters 17-48
Called from file "lib/HeterogenousList.re", line 94, characters 16-45
Called from file "lib/Brisk_reconciler_internal.re", line 975, characters 14-158
Called from file "lib/Brisk_reconciler_internal.re", line 735, characters 12-235
Called from file "lib/Brisk_reconciler_internal.re", line 1346, characters 14-401
Called from file "lib/Brisk_reconciler_internal.re", line 1090, characters 16-497
Called from file "lib/ListTR.re", line 32, characters 22-40
Called from file "lib/Brisk_reconciler_internal.re", line 1067, characters 10-1023
Called from file "lib/Brisk_reconciler_internal.re", line 915, characters 14-785
Called from file "lib/Brisk_reconciler_internal.re", line 735, characters 12-235
Called from file "lib/Brisk_reconciler_internal.re", line 1346, characters 14-401
Called from file "lib/Brisk_reconciler_internal.re", line 1090, characters 16-497
Called from file "lib/ListTR.re", line 32, characters 22-40
Called from file "lib/Brisk_reconciler_internal.re", line 1067, characters 10-1023
Called from file "lib/Brisk_reconciler_internal.re", line 915, characters 14-785
Called from file "lib/Brisk_reconciler_internal.re", line 735, characters 12-235
Called from file "lib/Brisk_reconciler_internal.re", line 1189, characters 12-180
Called from file "lib/Brisk_reconciler_internal.re", line 862, characters 12-236
Called from file "lib/Brisk_reconciler_internal.re", line 735, characters 12-235
Called from file "lib/Brisk_reconciler_internal.re", line 1545, characters 8-42
Called from file "lib/Brisk_reconciler_internal.re", line 1606, characters 6-124
Called from file "src/UI/Container.re", line 38, characters 10-64
Called from file "src/UI/Render.re", line 27, characters 17-56
Called from file "src/UI/Render.re", line 26, characters 2-99
Called from file "src/Core/Window.re", line 389, characters 2-17
Called from file "list.ml", line 110, characters 12-15
Called from file "src/Core/App.re", line 298, characters 6-123
Called from file "packages/reason-sdl2/src/sdl2.re", line 822, characters 10-20
Called from file "packages/reason-sdl2/src/sdl2.re", line 268, characters 17-59
Called from file "packages/reason-sdl2/src/sdl2.re", line 268, characters 17-59
Called from file "examples/Examples.re", line 378, characters 0-15                                                                           

It doesn't crash on master for me, so I assume that its because of these changes? Unless its just because this PR is lagging behind master a bit...

@CrossR
Copy link
Member

CrossR commented Oct 16, 2020

On Oni2 I'm not getting any crashes (from a basic opening it up and opening a few files etc) but I am missing out on window handles (or whatever the name is). I.e. the ability to drag the window around, and the resize on the edges.

@CrossR
Copy link
Member

CrossR commented Oct 20, 2020

Revery example is happy with the latest changes, I'm getting a crash now for Oni2 though:

[ERROR]  1524ms Oni2.Exception : Exception (Invalid_argument "compare: abstract value"):
Raised by primitive operation at file "src/UI/HitTest.re", line 10, characters 12-52
Called from file "src/Core/App.re", line 313, characters 16-43
Called from file "src/Core/App.re", line 313, characters 16-43
Called from file "packages/reason-sdl2/src/sdl2.re", line 822, characters 10-20
Called from file "packages/reason-sdl2/src/sdl2.re", line 268, characters 17-59
Called from file "packages/reason-sdl2/src/sdl2.re", line 268, characters 17-59
Called from file "src/bin_editor/Oni2_editor.re", line 497, characters 11-26

@bryphe
Copy link
Member

bryphe commented Oct 20, 2020

Thanks @CrossR !

Looks like the crash is occurring when we try to compare windows:

        if (sdlWindow == Window.getSdlWindow(window) && node#hasRendered()) {

Which, because they are wrapped in Abstract_val, is expected!

We'll need to have another way to compare windows - like using the https://wiki.libsdl.org/SDL_GetWindowID API

@bryphe
Copy link
Member

bryphe commented Nov 12, 2020

This is looking good now! Just need another round of cross-plat testing to make sure everything is OK

@zbaylin
Copy link
Member Author

zbaylin commented Nov 22, 2020

@bryphe I just merged this up with master and tested the example app and Oni out on macOS. All seemed to work well! I can also test on Linux and Windows!

I think it would be a good idea to get this merged before I start work on the native menus, since that will require passing pointers back and forth from the FFI a decent amount.

@zbaylin
Copy link
Member Author

zbaylin commented Nov 22, 2020

Windows works with both the Examples and Oni as of f2d6793 (the Window compare fix)

@bryphe
Copy link
Member

bryphe commented Nov 24, 2020

@bryphe I just merged this up with master and tested the example app and Oni out on macOS. All seemed to work well! I can also test on Linux and Windows!

Excellent! Sounds like you already verified on Windows - I'll try out on Linux.

I think it would be a good idea to get this merged before I start work on the native menus, since that will require passing pointers back and forth from the FFI a decent amount.

Right, that makes sense - I was just thinking about this change in the context of the NSObject PR 👍

@bryphe
Copy link
Member

bryphe commented Nov 24, 2020

Linux looks good! Sounds like we're all set with this 👍

@zbaylin zbaylin merged commit 5fe4207 into master Nov 24, 2020
@Et7f3 Et7f3 deleted the chore/native/pointer_wrap branch May 6, 2021 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants