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

Fixed webOS 1 crashes #315

Merged
merged 2 commits into from
Sep 21, 2023
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ set(BUILD_SHARED_CORE_LIBS OFF)

if (TARGET_WEBOS)
set(CMAKE_INSTALL_LIBDIR lib/backports)
set(SDL2_BACKPORT_REVISION "2876d3b86c2e3c5700003dfbf3a978be17cea078")
set(SDL2_BACKPORT_REVISION "24f705048c85a67100659816bc5c418fc3a284bc")
include(ExternalSDL2BackportForWebOS)
unset(CMAKE_INSTALL_LIBDIR)
else ()
Expand Down
6 changes: 5 additions & 1 deletion src/app/platform/webos/path_webos.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ char *path_pref() {
char *path_cache() {
const char *basedir = SDL_getenv("HOME");
char *cachedir = path_join(basedir, "cache");
path_dir_ensure(cachedir);
if (path_dir_ensure(cachedir) == -1) {
free(cachedir);
cachedir = strdup("/tmp/moonlight-tv-cache");
path_dir_ensure(cachedir);
}
return cachedir;
}
22 changes: 15 additions & 7 deletions src/app/ui/launcher/coverloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef struct img_loader_req_t {
#define DEBUG 0
#endif

static char *coverloader_cache_dir();
static const char *coverloader_cache_dir(coverloader_t *loader);

static GS_CLIENT coverloader_gs_client(coverloader_t *loader);

Expand Down Expand Up @@ -136,6 +136,7 @@ struct coverloader_t {
img_loader_t *base_loader;
lv_lru_t *mem_cache;
lazy_t client;
lazy_t cache_dir;
coverloader_req_t *reqlist;
refcounter_t refcounter;
};
Expand All @@ -151,6 +152,7 @@ coverloader_t *coverloader_new(app_t *app) {
loader->mem_cache = lv_lru_create(1024 * 1024 * 32, 720 * 1024, (lv_lru_free_t *) memcache_item_free, NULL);
loader->base_loader = img_loader_create(&coverloader_impl, app->backend.executor);
lazy_init(&loader->client, (lazy_supplier) app_gs_client_new, app);
lazy_init(&loader->cache_dir, (lazy_supplier) path_cache, NULL);
loader->reqlist = NULL;
return loader;
}
Expand All @@ -163,6 +165,10 @@ void coverloader_unref(coverloader_t *loader) {
if (client != NULL) {
gs_destroy(client);
}
char *cache_dir = lazy_deinit(&loader->cache_dir);
if (cache_dir != NULL) {
free(cache_dir);
}
img_loader_destroy(loader->base_loader);
lv_lru_del(loader->mem_cache);
refcounter_destroy(&loader->refcounter);
Expand Down Expand Up @@ -193,20 +199,19 @@ void coverloader_display(coverloader_t *loader, const uuidstr_t *uuid, int id, l
req->task = task;
}

static char *coverloader_cache_dir() {
return path_cache();
static const char *coverloader_cache_dir(coverloader_t *loader) {
return lazy_obtain(&loader->cache_dir);
}

static GS_CLIENT coverloader_gs_client(coverloader_t *loader) {
return lazy_obtain(&loader->client);
}

static void coverloader_cache_item_path(char path[4096], const coverloader_req_t *req) {
char *cachedir = coverloader_cache_dir();
const char *cachedir = coverloader_cache_dir(req->loader);
char basename[128];
SDL_snprintf(basename, 128, "%s_%d", (char *) &req->server_id, req->id);
path_join_to(path, 4096, cachedir, basename);
free(cachedir);
}

static bool coverloader_memcache_get(coverloader_req_t *req) {
Expand Down Expand Up @@ -289,13 +294,16 @@ static bool coverloader_filecache_get(coverloader_req_t *req) {
char path[4096];
coverloader_cache_item_path(path, req);
SDL_Surface *decoded = IMG_Load(path);
if (!decoded) { return false; }
if (!decoded) {
commons_log_warn("CoverLoader", "Failed to load cover from %s: %s", path, IMG_GetError());
return false;
}
if (cover_is_placeholder(decoded)) {
SDL_FreeSurface(decoded);
return false;
}
if (decoded->format->palette != NULL) {
SDL_Surface* true_color = SDL_ConvertSurfaceFormat(decoded, SDL_PIXELFORMAT_RGB24, 0);
SDL_Surface *true_color = SDL_ConvertSurfaceFormat(decoded, SDL_PIXELFORMAT_RGB24, 0);
SDL_FreeSurface(decoded);
if (true_color == NULL) {
return false;
Expand Down
8 changes: 5 additions & 3 deletions src/app/util/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ void path_join_to(char *dest, size_t maxlen, const char *parent, const char *bas
snprintf(dest, maxlen, "%.*s%c%s", parentlen, parent, PATH_SEPARATOR, basename);
}

void path_dir_ensure(const char *dir) {
if (access(dir, F_OK) == -1) {
int path_dir_ensure(const char *dir) {
if (access(dir, F_OK | W_OK) == -1) {
if (errno == ENOENT) {
MKDIR(dir, 0755);
return MKDIR(dir, 0755);
}
return -1;
}
return 0;
}
2 changes: 1 addition & 1 deletion src/app/util/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ char *path_pref();

char *path_cache();

void path_dir_ensure(const char *dir);
int path_dir_ensure(const char *dir);
8 changes: 8 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
static int settings_load(app_settings_t *settings);

int main(int argc, char *argv[]) {
#if TARGET_WEBOS
if (getenv("EGL_PLATFORM") == NULL) {
setenv("EGL_PLATFORM", "wayland", 0);
}
if (getenv("XDG_RUNTIME_DIR") == NULL) {
setenv("XDG_RUNTIME_DIR", "/tmp/xdg", 0);
}
#endif
app_t app;
int ret = app_init(&app, settings_load, argc, argv);
if (ret != 0) {
Expand Down
2 changes: 1 addition & 1 deletion third_party/commons