Skip to content

Commit

Permalink
[html] Display app errors in HTML
Browse files Browse the repository at this point in the history
[plugins] Fix scripts to account for unzip function changes
[core] Fix TTFont init
  • Loading branch information
hgy29 committed Apr 24, 2017
1 parent f40ae40 commit c8e2ba3
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 8 deletions.
4 changes: 2 additions & 2 deletions 2dsg/ttfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ void TTFont::constructor(const char *filename, float size, float smoothing)
args.flags = FT_OPEN_STREAM;
args.stream = &stream_;

smoothing_ = smoothing;

if (FT_Open_Face(FT_Library_Singleton::instance(), &args, 0, &face_))
throw GiderosException(GStatus(6012, filename)); // Error #6012: %s: Error while reading font file.

Expand All @@ -95,8 +97,6 @@ void TTFont::constructor(const char *filename, float size, float smoothing)
currentLogicalScaleX_=scalex;
currentLogicalScaleY_=scaley;
defaultSize_=size;

smoothing_ = smoothing;
}

void TTFont::checkLogicalScale()
Expand Down
4 changes: 2 additions & 2 deletions emscripten/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ $(BUILD)/lib%.a:
@echo "EMAR" $@
@$(EMAR) r $@ $^

$(BUILD)/gideros.js: $(SUBLIBS_AR) $(OBJS) gidjs.js gui.js gidshell.html
$(BUILD)/gideros.js: $(SUBLIBS_AR) $(OBJS) gidjs.js gui.js gidpost.js gidshell.html
@echo "EMLINK gideros"
@$(EMCC) $(OBJS) $(LIBS) $(addprefix -s ,$(EOPTS)) $(OPTS) $(SUBLIBS_AR) -o $(BUILD)/gideros.html --pre-js gidjs.js --pre-js gui.js --shell-file gidshell.html
@$(EMCC) $(OBJS) $(LIBS) $(addprefix -s ,$(EOPTS)) $(OPTS) $(SUBLIBS_AR) -o $(BUILD)/gideros.html --pre-js gidjs.js --pre-js gui.js --post-js gidpost.js --shell-file gidshell.html

main: path $(BUILD)/gideros.js
cp gideros.png $(TEMPLATE)
Expand Down
1 change: 1 addition & 0 deletions emscripten/applicationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ bool hasDocuments=EM_ASM_INT_V( {return FS.documentsOk;}
else
{
EM_ASM_( { Module.luaError(Pointer_stringify($0)) }, error);
throw luaException(error);
// g_exit();
}
}
Expand Down
18 changes: 18 additions & 0 deletions emscripten/applicationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
#include <stdlib.h>
#include "netplayer.h"

#include <exception>

using namespace std;

class luaException: public exception
{
public:
luaException(const char *trace) throw()
:trace(trace) {}
virtual const char* what() const throw()
{
return trace.c_str();
}
virtual ~luaException() throw() {}
private:
string trace;
};

struct ProjectProperties {
ProjectProperties() {
scaleMode = 0;
Expand Down
1 change: 0 additions & 1 deletion emscripten/gidjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Module.preRun.push(function() {
Module['addRunDependency'](p);
xhr.send();
}); });

Module.setStatus("Loading application...");
//Load GAPP if supplied
Module.hasGApp=((typeof(GAPP_URL) != 'undefined')&&(GAPP_URL!=null));
Expand Down
4 changes: 4 additions & 0 deletions emscripten/gidpost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abortDecorators.push(function (what)
{
Module.gidAbort(what);
});
35 changes: 35 additions & 0 deletions emscripten/gidshell.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
</div>
</figure>
</div>
<div id="oops" class="fullscreen oops" style="display: none">
<h1>Ooops, something went wrong...</h1>
<div id="memoryErr" style="display: none">
<h3>This app ran out of memory</h3>
Try to close some other apps or tabs in your browser and try again.
</div>
<div id="luaErr" style="display: none">
<h3>An error occured in the code</h3>
Please inform the app developer about the details below, they will help him fix this in the future.
</div>
<div id="genErr" style="display: none">
<h3>An unexpected error occured</h3>
The details below may be helpful to you or the app developer... hopefully.
</div>
<pre id="errDetails">
</pre>
</div>
<!-- Put canvas on top of everything so that it catches events -->
<canvas class="fullscreen" id="canvas" oncontextmenu="event.preventDefault()"
hidden=1></canvas>
Expand Down Expand Up @@ -62,10 +79,13 @@
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');
var infopaneElement = document.getElementById('infopane');
var errDetailsElement = document.getElementById('errDetails');
var oopsElement = document.getElementById('oops');

var Module = {
preRun: [],
postRun: [],
preInit: [],
TOTAL_MEMORY: GIDEROS_MEMORY_MB*1024*1024,
dynamicLibraries: [ /*GIDEROS_DYNLIB_PLUGIN*/ null ],
JSPlugins: [ /*GIDEROS_JS_PLUGIN*/ null ],
Expand Down Expand Up @@ -107,6 +127,20 @@

return canvas;
})(),
showError: function(type,detail) {
spinnerElement.hidden = true;
infopaneElement.style.display="none";
canvas.hidden = true;
oopsElement.style.display="block";
errDetailsElement.innerHTML=detail;
document.getElementById(type).style.display="block";
},
gidAbort: function (what) {
if (what.includes('ALLOW_MEMORY_GROWTH=1'))
Module.showError("memoryErr",what);
else
Module.showError("genErr",what);
},
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.text) return;
Expand Down Expand Up @@ -149,6 +183,7 @@
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
//Module.showError("genErr","");
};
</script>
{{{ SCRIPT }}}
Expand Down
44 changes: 43 additions & 1 deletion emscripten/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ EGLDisplay display;
#endif
float pixelRatio=1.0;

static void errorAbort(const char *detail)
{
const char *type="genErr";
EM_ASM_( { Module.showError(Pointer_stringify($0),Pointer_stringify($1)) }, type, detail);
emscripten_force_exit(1);
}

static void errorLua(const char *detail)
{
const char *type="luaErr";
EM_ASM_( { Module.showError(Pointer_stringify($0),Pointer_stringify($1)) }, type, detail);
emscripten_force_exit(1);
}

int initGL(int width, int height)
{
//emscripten_set_canvas_size(width,height);
Expand Down Expand Up @@ -78,12 +92,26 @@ int initGL(int width, int height)
extern "C" void GGStreamOpenALTick();
void looptick()
{
s_applicationManager->drawFrame();
try {
s_applicationManager->drawFrame();
#ifndef EGL
glfwSwapBuffers();
#else
eglSwapInterval(display,1);
#endif
}
catch(const luaException& e)
{
errorLua(e.what());
}
catch(const std::exception& e)
{
errorAbort(e.what());
}
catch(...)
{
errorAbort("Generic error");
}
}

EM_BOOL resize_callback(int eventType, const EmscriptenUiEvent *e, void *userData)
Expand Down Expand Up @@ -233,6 +261,7 @@ extern const char *codeKey_;
const char *currentUrl=NULL;
int main() {
EM_ASM(Module.setStatus("Initializing"));
try {

char *url=(char *) EM_ASM_INT_V({
return allocate(intArrayFromString(location.href), 'i8', ALLOC_STACK);
Expand Down Expand Up @@ -313,6 +342,19 @@ char *url=(char *) EM_ASM_INT_V({
s_applicationManager->surfaceChanged(defWidth,defHeight,(defWidth>defHeight)?90:0);
emscripten_set_main_loop(looptick, 0, 1);
main_registerPlugin(NULL);
}
catch(const luaException& e)
{
errorLua(e.what());
}
catch(const std::exception& e)
{
errorAbort(e.what());
}
catch(...)
{
errorAbort("Generic error");
}
}

int main_registerPlugin(const char *pname)
Expand Down
2 changes: 1 addition & 1 deletion plugins/Facebook/Facebook.gplugin
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<target name="iOS">
<template name="binaries" path="[[[sys.pluginDir]]]/source/iOS/Plugins/" dest="[[[project.namews]]]/Plugins/" />
<download source="http://apps.giderosmobile.com/ext/ios/FacebookSDK.framework-3.24.4.zip" dest="[[[sys.cacheDir]]]/FacebookSDK.framework.zip" />
<unzip source="[[[sys.cacheDir]]]/FacebookSDK.framework.zip" dest="[[[project.namews]]]/Plugins/Facebook/FacebookSDK.framework" />
<unzip source="[[[sys.cacheDir]]]/FacebookSDK.framework.zip" dest="[[[project.namews]]]/Plugins/Facebook" />
<template name="Project" path="">
<replacelist wildcards="project.pbxproj;EAGLView.m;[[[project.namews]]]-Info.plist">
<prepend>
Expand Down
2 changes: 1 addition & 1 deletion plugins/ads/ads.gplugin
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ iOSProject.commit()
<if condition="[[[plugin.adsFwUnity]]]">
<template name="Unity Ads" path="[[[local.adsfws]]]" dest="[[[local.adsfwd]]]" include="AdsUnity.*" exclude="*.framework" />
<download source="http://apps.giderosmobile.com/ext/ios/UnityAds.framework-2.0.5.zip" dest="[[[sys.cacheDir]]]/UnityAds.framework.zip" />
<unzip source="[[[sys.cacheDir]]]/UnityAds.framework.zip" dest="[[[local.adsfwd]]]/UnityAds.framework" />
<unzip source="[[[sys.cacheDir]]]/UnityAds.framework.zip" dest="[[[local.adsfwd]]]" />
<lua><![CDATA[
local iOSProject=require("Tools/export_ios")
iOSProject.addSources({
Expand Down

0 comments on commit c8e2ba3

Please sign in to comment.