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

Examples on asm.js #383

Open
bullno1 opened this issue May 12, 2015 · 14 comments
Open

Examples on asm.js #383

bullno1 opened this issue May 12, 2015 · 14 comments
Labels

Comments

@bullno1
Copy link
Contributor

bullno1 commented May 12, 2015

Due to the use of while(true), none of the examples work on asm.js.

To suport emscripten_set_main_loop, all examples will have to be rewritten. The lack of a stack makes it quite troublesome. Local variables will have to become static or instance variables.

@bkaradzic
Copy link
Owner

Yup, that's why it's not supported yet... 17-drawstress work.

@bkaradzic bkaradzic added the bug label May 22, 2015
@RichardGale
Copy link
Contributor

+1 vote for statics.

@bkaradzic
Copy link
Owner

@RichardGale Another problem is that resources have to be downloaded since there is no file system. Most of examples require some assets to be loaded.

@RichardGale
Copy link
Contributor

Latest emscripten could make this problem easier to solve than other platforms.

If you add --preload-file [directory of resources] to emcc during finalization that entire directory is packed into a virtual file system that is automatically mounted by the Javascript. Then fopen() and other calls "just work".

Any other known issues?

@bkaradzic
Copy link
Owner

That's cool, nope. I just need to create init/update/shutdown for all examples, instead main with while loop.

@bkaradzic
Copy link
Owner

Do you know did they fix setjmp/longjmp?

Also if they add pthreads, that would also fix examples.

@RichardGale
Copy link
Contributor

I don't know the state of setjmp/longjmp as I stopped using them. pthreads are experimental (emscripten-core/emscripten-fastcomp#67).

I took a look at drawstress and the transformation seemed:

  1. move process events while loop contents into a separate function
  2. mainloop calls loop.
  3. set loop for emscripten, while(1) for all other platforms
  4. resolve variables due to 1)
    and am thinking of looking at the other examples too.

@bkaradzic
Copy link
Owner

If setjmp/longjmp works no change to will be necessary... It could be faked with it.

@bkaradzic
Copy link
Owner

I had this before, but it didn't work:
https://searchcode.com/codesearch/view/26623312/

extern int _main_(int _argc, char** _argv);

static jmp_buf s_main;
static jmp_buf s_loop;

void emscripten_yield()
{
    if (!setjmp(s_main) )
    {
        longjmp(s_loop, 1);
    }
}

void loop()
{
    if (!setjmp(s_loop) )
    {
        longjmp(s_main, 1);
    }
}

int main(int _argc, char** _argv)
{
    if (!setjmp(s_loop) )
    {
        alloca(16<<10);
        _main_(_argc, _argv);
    }

    emscripten_set_main_loop(loop, 10, true);
}

Then in while loop just call (and it should work with any example):

emscripten_yield();

If this works, then I'll bury that emscripten_yield() somewhere in entry.cpp.

@RichardGale
Copy link
Contributor

State of play:

Code that uses low-level features of the native environment, for example native stack manipulation in conjunction with setjmp/longjmp (we support normal setjmp/longjmp, but not with stack replacing, etc.)

https://kripken.github.io/emscriptem-site/docs/porting/guidelines/portability_guidelines.html

I'll try your code in my app.

@RichardGale
Copy link
Contributor

Integrated with example-00-helloworld and got:

uncaught exception: longjmp

@bkaradzic
Copy link
Owner

@bkaradzic
Copy link
Owner

This works, you just need to uncomment and rebuild:
bkaradzic/bx@a611d0b
f9e63f1

It's slow, but it can get you to other examples until I change them to have init/update/shutdown.

@bkaradzic
Copy link
Owner

I fixed a few examples to work with emscripten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants