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

fixing the crash issue on windows #34

Merged
merged 1 commit into from
Jan 30, 2024
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: threeBrain
Type: Package
Title: 3D Brain Visualization
Version: 1.0.1.9107
Version: 1.0.1.9108
Authors@R: c(
person("Zhengjia", "Wang", email = "[email protected]", role = c("aut", "cre", "cph")),
person("John", "Magnotti", email = "[email protected]", role = c("aut", "res")),
Expand Down
19 changes: 13 additions & 6 deletions R/simple_server.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
ensure_simple_server <- function(dir = file.path(tempdir(), "threeBrainViewer")) {
app <- getOption("threeBrain.viewer.app", NULL)
if(!is.list(app) || !isTRUE(app$is_threeBrain_viewer_app)) {
is_served <- is.list(app) && isTRUE(app$is_threeBrain_viewer_app)
host <- getOption("threeBrain.viewer.host", "127.0.0.1")
if( !is_served || !identical(app$host, host) ) {
if(!dir.exists(dir)) { dir.create(dir) }
if( is_served ) {
tryCatch({ app$stop_server() }, error = function(e) {})
}
app <- tryCatch({
port <- getOption("threeBrain.viewer.port", servr::random_port(n = 200))
app <- servr::httd(dir = dir, browser = FALSE, port = port)
app <- servr::httd(host = host, dir = dir, browser = FALSE, port = port)
app
}, error = function(e) {
message("Trying another port.")
app <- servr::httd(dir = dir, browser = FALSE)
app <- servr::httd(host = host, dir = dir, browser = FALSE)
app
})
app$is_threeBrain_viewer_app <- TRUE
options("threeBrain.viewer.app" = app)
options("threeBrain.viewer.port" = app$port)
options("threeBrain.viewer.host" = app$host)
}

# app might be stopped, hence we need to restart if that's true
Expand All @@ -23,7 +29,7 @@ ensure_simple_server <- function(dir = file.path(tempdir(), "threeBrainViewer"))
# use servr to check if port is available. The server might be shutdown but
# the flag is still on
tryCatch({
servr::random_port(port = app$port, n = 0)
servr::random_port(host = host, port = app$port, n = 0)
is_running <- FALSE
}, error = function(e) {
})
Expand All @@ -32,16 +38,17 @@ ensure_simple_server <- function(dir = file.path(tempdir(), "threeBrainViewer"))
# the server has stopped running, start a new server
app <- tryCatch({
port <- getOption("threeBrain.viewer.port", servr::random_port(n = 200))
app <- servr::httd(dir = dir, browser = FALSE, port = port)
app <- servr::httd(host = host, dir = dir, browser = FALSE, port = port)
app
}, error = function(e) {
message("Trying another port.")
app <- servr::httd(dir = dir, browser = FALSE)
app <- servr::httd(host = host, dir = dir, browser = FALSE)
app
})
app$is_threeBrain_viewer_app <- TRUE
options("threeBrain.viewer.app" = app)
options("threeBrain.viewer.port" = app$port)
options("threeBrain.viewer.host" = app$host)
}

app
Expand Down
2 changes: 1 addition & 1 deletion inst/threeBrainJS/dist/threebrain.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/threeBrainJS/dist/threebrain.js.map

Large diffs are not rendered by default.

Loading