Merge pull request #3 from moronigranja/bad-format-crash-fix-pr

Bad format crash fix pr
This commit is contained in:
SeanOMik 2019-10-30 12:43:39 -05:00 committed by GitHub
commit 123e513394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 14 deletions

View File

@ -47,9 +47,9 @@ static void save_last_page(const char *book_name, int current_page) {
} }
} }
BookReader::BookReader(const char *path) { BookReader::BookReader(const char *path, int* result) {
if (ctx == NULL) { if (ctx == NULL) {
ctx = fz_new_context(NULL, NULL, 128 << 10); ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
fz_register_document_handlers(ctx); fz_register_document_handlers(ctx);
} }
@ -62,16 +62,33 @@ BookReader::BookReader(const char *path) {
book_name.erase(std::remove(book_name.begin(), book_name.end(), c), book_name.end()); book_name.erase(std::remove(book_name.begin(), book_name.end(), c), book_name.end());
} }
fz_try(ctx) {
std::cout << "fz_open_document" << std::endl; std::cout << "fz_open_document" << std::endl;
doc = fz_open_document(ctx, path); doc = fz_open_document(ctx, path);
if (!doc)
{
std::cout << "Error opening file!" << std::endl;
*result = -1;
return;
}
int current_page = load_last_page(book_name.c_str()); int current_page = load_last_page(book_name.c_str());
//int current_page = 0; //int current_page = 0;
std::cout << "current_page = " << current_page << std::endl;
switch_current_page_layout(_currentPageLayout, current_page); switch_current_page_layout(_currentPageLayout, current_page);
if (current_page > 0) { if (current_page > 0) {
show_status_bar(); show_status_bar();
} }
}
fz_catch(ctx){
std::cout << "fz_catch reached, closing gracefully" << std::endl;
*result = -2;
return;
}
} }
BookReader::~BookReader() { BookReader::~BookReader() {

View File

@ -14,7 +14,7 @@ typedef enum {
class BookReader { class BookReader {
public: public:
BookReader(const char *path); BookReader(const char *path, int *result);
~BookReader(); ~BookReader();
bool permStatusBar = false; bool permStatusBar = false;

View File

@ -10,14 +10,21 @@ extern "C" {
#include "BookReader.hpp" #include "BookReader.hpp"
void Menu_OpenBook(char *path) { void Menu_OpenBook(char *path) {
BookReader *reader = new BookReader(path); BookReader *reader = NULL;
int result = 0;
reader = new BookReader(path, &result);
if(result < 0){
std::cout << "Menu_OpenBook: document not loaded" << std::endl;
}
/*TouchInfo touchInfo; /*TouchInfo touchInfo;
Touch_Init(&touchInfo);*/ Touch_Init(&touchInfo);*/
bool helpMenu = false; bool helpMenu = false;
while(appletMainLoop()) { while(result >= 0 && appletMainLoop()) {
reader->draw(helpMenu); reader->draw(helpMenu);
hidScanInput(); hidScanInput();