nicos-angelopoulos / real

Integrative statistics with R and logic programming
http://stoics.org.uk/~nicos/sware/real
4 stars 1 forks source link

Plots hang on macOS #2

Closed esad closed 2 years ago

esad commented 4 years ago

Calling e.g. <- plot(c(1,2,3)) will open a new window, but it's completely unresponsive. I also tried calling plot in another thread withthread_create(<- plot(c(1,2,3)), _Id)., which crashes with the following stacktrace:

Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.20.106/AppKit.subproj/NSView.m, line 14480.

SWI-Prolog [thread -1 () at Tue May 19 13:26:32 2020]: received fatal signal 4 (ill)
C-stack trace labeled "crash":
  [0] /usr/local/Cellar/swipl/8.1.21/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(save_backtrace+0x65) [0x10384bb75]
  [1] /usr/local/Cellar/swipl/8.1.21/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(print_c_backtrace+0xf) [0x10384c1db]
  [2] /usr/local/Cellar/swipl/8.1.21/lib/swipl/lib/x86_64-darwin/libswipl.8.dylib(sigCrashHandler+0xb7) [0x10384c122]
...
nicos-angelopoulos commented 4 years ago

Sorry. Not a Mac user. There are a couple of Mac users at the SWI-Prolog forum: https://swi-prolog.discourse.group/

See also archives of SWI forum (both discourse and before).

Thanks for report.

NA

On Tue, 19 May 2020 04:26:03 -0700 Esad Hajdarevic notifications@github.com wrote:

Calling e.g. <- plot(c(1,2,3)) will open a new window, but it's completely unresponsive.

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/nicos-angelopoulos/real/issues/2

esad commented 4 years ago

Hi! I'm working on a fix, as having plots from SWI-Prolog would be really handy. What platform are you using? Does the UI work there with real - can you resize and move the plot window etc.?

esad commented 4 years ago

So it seems that R_ProcessEvents should be called regularly to service the UI events like windows etc. It's exposed in R through process.events(), which we can call via real from Prolog:

r_ui_loop :-
  <- invisible(process.events()),
  alarm(0.1, r_ui_loop, _, [install(true), remove(true)]).

Now we can start the timer in the background with r_ui_loop. from toplevel and enjoy the plots :)

esad commented 4 years ago

I am not sure if other platforms somehow install the UI handler automatically and if this is Mac-specific. If not, maybe we could add the UI loop by default to r_init or even move it to C code.

nicos-angelopoulos commented 4 years ago

Dear Esad,

Glad you resolved this. Will be getting a Mac in a few weeks, so might have opportunity to incorporate this. Please contact via http://stoics.org.uk/~nicos/sware/contact.html for a chat.

Thanks for using Real,

Nicos

On Wed, 20 May 2020 00:25:19 -0700 Esad Hajdarevic notifications@github.com wrote:

So it seems that R_ProcessEvents should be called regularly to service the UI events like windows etc. It's exposed in R through process.events(), which we can call via real from Prolog:

r_ui_loop :-
  <- invisible(process.events()),
  alarm(0.1, r_ui_loop, _, [install(true), remove(true)]).

Now we can start the timer in the background with r_ui_loop. from toplevel and enjoy the plots :)

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/nicos-angelopoulos/real/issues/2#issuecomment-631289290

esad commented 4 years ago

Hi Nicos,

it's not completely resolved yet. I've stumbled upon issue where running an alarm handler in the loop causes problem with socket connections, see https://swi-prolog.discourse.group/t/running-alarm-in-a-loop-causes-socket-already-connected-errors/2378 - I think I found the cause and have submitted patch to clib package.

Also the handler should probably be invoked directly via send_r_command to avoid emitting debug messages for process.events().

Have you ever used real on other platform to do interactive stuff like plots? I'm wondering how it ever worked without explicit call to process the events.

esad commented 4 years ago

And yes, thank you very much for your work on real! It's amazing to be able to integrate Prolog and R this seamlessly.

nicos-angelopoulos commented 4 years ago

Hi Esad,

Yes. Real works reasonably well with Linux and (as far as i know) Windoz plots. You don't usually manipulate the plot windows yourself. You typically create the plot window via commands from the SWI prompt/programs.

eg. ?- <- plot( c(1,2,3) ).

will create a new window and place the plot there. Under linux you cannot manipulate this manually (eg maximising to full screen will make the plot within disappear). But this is not really a limitation, as you can create any size with x11().

eg

?- <- x11(width=14,height=7). ?- <- plot( c(1,2,3) ).

There are some expert Mac users on the SWI-Prolog forum, if you are still having problems.

Nicos

On Sat, 23 May 2020 13:46:06 -0700 Esad Hajdarevic notifications@github.com wrote:

Hi Nicos,

it's not completely resolved yet. I've stumbled upon issue where running an alarm handler in the loop causes problem with socket connections, see https://swi-prolog.discourse.group/t/running-alarm-in-a-loop-causes-socket-already-connected-errors/2378 - I think I found the cause and have submitted patch to clib package.

Also the handler should probably be invoked directly via send_r_command to avoid emitting debug messages for process.events().

Have you ever used real on other platform to do interactive stuff like plots? I'm wondering how it ever worked without explicit call to process the events.

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/nicos-angelopoulos/real/issues/2#issuecomment-633136914

esad commented 4 months ago

Hi Nicos, plots are still not working on Mac, did you maybe find a solution in the meantime?

nicos-angelopoulos commented 4 months ago

Sorry, I have no access to Macs. Happy to consider patches. If you are building from sources, it could be not too difficult to investigate.

Regards,

Nicos

On Mon, 13 May 2024 08:50:33 -0700 Esad Hajdarevic @.***> wrote:

Hi Nicos, plots are still not working on Mac, did you maybe find a solution in the meantime?