Unverified Commit da3481af authored by Libretro-Admin's avatar Libretro-Admin Committed by GitHub
Browse files

Merge pull request #32 from phcoder/and

Fix crash on Android
parents d1b83282 733f64f8
......@@ -22,7 +22,6 @@ static retro_audio_sample_batch_t audio_batch_cb;
retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
retro_input_state_t input_state_cb;
static retro_log_printf_t log_cb;
unsigned game_width = 640;
unsigned game_height = 480;
......@@ -38,6 +37,8 @@ static void fallback_log(enum retro_log_level level, const char *fmt, ...)
va_end(va);
}
retro_log_printf_t log_cb = fallback_log;
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
static bool fb_ready = false;
static bool init_program_now = true;
......@@ -145,8 +146,6 @@ void retro_set_environment(retro_environment_t cb)
if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
log_cb = logging.log;
else
log_cb = fallback_log;
}
void retro_set_audio_sample(retro_audio_sample_t cb)
......@@ -264,6 +263,7 @@ static void check_variables(bool first_time_startup)
static unsigned logic_frames = 0;
static unsigned amount_frames = 0;
static bool dead = false;
extern void on_key(void);
......@@ -272,6 +272,11 @@ void retro_run(void)
static unsigned timestep = 0;
static double libretro_on_key_delay = 0.0f;
bool updated = false;
if (dead) {
environ_cb (RETRO_ENVIRONMENT_SHUTDOWN, NULL);
return;
}
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
check_variables(false);
......@@ -282,7 +287,12 @@ void retro_run(void)
}
if (init_program_now)
{
main_load_game(0, NULL);
if (main_load_game(0, NULL) < 0) {
log_cb(RETRO_LOG_ERROR, "Game init failed\n");
environ_cb (RETRO_ENVIRONMENT_SHUTDOWN, NULL);
dead = true;
return;
}
init_program_now = false;
video_cb(NULL, game_width, game_height, 0);
return;
......@@ -304,7 +314,10 @@ void retro_run(void)
if (main_run() != 1)
{
/* Do shutdown or something similar. */
log_cb(RETRO_LOG_INFO, "main_run failed. Shutting down\n");
environ_cb (RETRO_ENVIRONMENT_SHUTDOWN, NULL);
dead = true;
return;
}
timestep += 1;
......
......@@ -10,6 +10,7 @@
#define SCROLL_THRESHOLD 0.1
#define MAX_MESSAGES 4
#define DB_PATH "craft.db"
#define DB_AUTH_PATH "auth.db"
#define USE_CACHE 1
#define DAY_LENGTH 600
#define INVERT_MOUSE 0
......
......@@ -36,10 +36,10 @@ int get_db_enabled() {
return db_enabled;
}
int db_init(char *path)
int db_init(char *path, char *auth_path)
{
static const char *attach_query = "attach database ? as auth;";
static const char *create_query =
"attach database 'auth.db' as auth;"
"create table if not exists auth.identity_token ("
" username text not null,"
" token text not null,"
......@@ -113,12 +113,26 @@ int db_init(char *path)
static const char *set_key_query =
"insert or replace into key (p, q, key) "
"values (?, ?, ?);";
sqlite3_stmt *attach_stmt;
int rc;
if (!db_enabled) {
return 0;
}
rc = sqlite3_open(path, &db);
if (rc) return rc;
rc = sqlite3_prepare_v2(
db, attach_query, -1, &attach_stmt, NULL);
if (rc) return rc;
rc = sqlite3_bind_text(attach_stmt, 1, auth_path, -1, NULL);
if (rc) return rc;
do
rc = sqlite3_step(attach_stmt);
while (rc == SQLITE_ROW);
if (rc && rc != SQLITE_DONE) return rc;
rc = sqlite3_finalize(attach_stmt);
if (rc) return rc;
rc = sqlite3_exec(db, create_query, NULL, NULL, NULL);
if (rc) return rc;
rc = sqlite3_prepare_v2(
......
......@@ -7,7 +7,7 @@
void db_enable();
void db_disable();
int get_db_enabled();
int db_init(char *path);
int db_init(char *path, char *auth_path);
void db_close();
void db_commit();
void db_auth_set(char *username, char *identity_token);
......
......@@ -26,6 +26,7 @@
#ifdef __LIBRETRO__
#include <retro_miscellaneous.h>
extern retro_log_printf_t log_cb;
#endif
#include "../textures/font_texture.h"
......@@ -136,6 +137,7 @@ typedef struct {
int mode;
int mode_changed;
char db_path[MAX_PATH_LENGTH];
char db_auth_path[MAX_PATH_LENGTH];
char server_addr[MAX_ADDR_LENGTH];
int server_port;
int day_length;
......@@ -2689,9 +2691,12 @@ static void main_set_db_path(void)
char slash = '/';
#endif
snprintf(g->db_path, MAX_PATH_LENGTH, "%s%c%s", dir, slash, DB_PATH);
snprintf(g->db_auth_path, MAX_PATH_LENGTH, "%s%c%s", dir, slash, DB_AUTH_PATH);
}
else
else {
snprintf(g->db_path, MAX_PATH_LENGTH, "%s", DB_PATH);
snprintf(g->db_auth_path, MAX_PATH_LENGTH, "%s", DB_AUTH_PATH);
}
}
static void parse_command(const char *buffer, int forward)
......@@ -3374,9 +3379,14 @@ int main_load_game(int argc, char **argv)
// DATABASE INITIALIZATION //
if (g->mode == MODE_OFFLINE || USE_CACHE)
{
int rc;
db_enable();
if (db_init(g->db_path))
rc = db_init(g->db_path, g->db_auth_path);
if (rc) {
log_cb(RETRO_LOG_ERROR, "Error initing db %s+%s: %d\n",
g->db_path, g->db_auth_path, rc);
return -1;
}
if (g->mode == MODE_ONLINE) {
// TODO: support proper caching of signs (handle deletions)
db_delete_all_signs();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment