Merge pull request #3 from moronigranja/bad-format-crash-fix-pr
Bad format crash fix pr
This commit is contained in:
commit
123e513394
|
@ -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) {
|
||||
ctx = fz_new_context(NULL, NULL, 128 << 10);
|
||||
ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
|
||||
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());
|
||||
}
|
||||
|
||||
fz_try(ctx) {
|
||||
std::cout << "fz_open_document" << std::endl;
|
||||
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 = 0;
|
||||
|
||||
std::cout << "current_page = " << current_page << std::endl;
|
||||
|
||||
switch_current_page_layout(_currentPageLayout, current_page);
|
||||
|
||||
if (current_page > 0) {
|
||||
show_status_bar();
|
||||
}
|
||||
}
|
||||
fz_catch(ctx){
|
||||
std::cout << "fz_catch reached, closing gracefully" << std::endl;
|
||||
*result = -2;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BookReader::~BookReader() {
|
||||
|
|
|
@ -14,7 +14,7 @@ typedef enum {
|
|||
|
||||
class BookReader {
|
||||
public:
|
||||
BookReader(const char *path);
|
||||
BookReader(const char *path, int *result);
|
||||
~BookReader();
|
||||
|
||||
bool permStatusBar = false;
|
||||
|
|
|
@ -10,14 +10,21 @@ extern "C" {
|
|||
#include "BookReader.hpp"
|
||||
|
||||
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;
|
||||
Touch_Init(&touchInfo);*/
|
||||
|
||||
bool helpMenu = false;
|
||||
|
||||
while(appletMainLoop()) {
|
||||
while(result >= 0 && appletMainLoop()) {
|
||||
reader->draw(helpMenu);
|
||||
|
||||
hidScanInput();
|
||||
|
|
Loading…
Reference in New Issue