<https://lh5.googleusercontent.com/-g4Pi0NcSSCE/U0I0i9ff4XI/AAAAAAAAAAs/aAOV86ZP_yE/s1600/sdlquit+ignored.JPG>
Thanks that really made things clearer for me. The only thing is now I'm
wondering why calling SDL_Quit() fails and spits out *"SDL_Quit called (and
ignored)" *(thus the need for exit(0) after it):
Here's the code now:
#include <stdio.h>
> #include <stdlib.h>
> #include <SDL/SDL.h>
> #include <emscripten.h>
>
> SDL_Surface* bitmap = SDL_LoadBMP("bat.bmp");
> SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 0, SDL_HWSURFACE |
> SDL_DOUBLEBUF );
> SDL_Rect source;
> SDL_Rect destination;
> bool gameRunning = true;
>
> void renderStuff() {
>
> SDL_BlitSurface(bitmap, &source, screen, &destination);
> SDL_Flip(screen);
>
> }
>
> void one_iter() {
>
>
> SDL_Event event;
>
> if (SDL_PollEvent(&event))
> {
> if (event.type == SDL_KEYUP)
> {
> gameRunning = false;
> printf("Game Stopping!!!!!!\n");
> SDL_Quit();
> exit(0);
> }
> }
> printf("Game Running..\n");
>
>
> renderStuff();
>
>
> }
>
> int main(int argc, char **argv)
> {
> SDL_Init( SDL_INIT_VIDEO );
>
>
>
> // Part of the bitmap that we want to draw
>
> source.x = 24;
> source.y = 63;
> source.w = 65;
> source.h = 44;
>
> // Part of the screen we want to draw the sprite to
>
> destination.x = 100;
> destination.y = 100;
> destination.w = 65;
> destination.h = 44;
>
> emscripten_set_main_loop(one_iter, 60, 1);
>
> return 0;
> }
>
I'm sure I must be using it wrong or something. I'm aware that it's not the
same thing as the real SDL_Quit() but I'm not familiar with how it works
with emscripten_set_main_loop.
On Sunday, April 6, 2014 8:18:59 PM UTC-5, Alon Zakai wrote:
>
> Looks like that code is calling SDL_Init and InitVideo in each frame? That
> is going to be slow, and also allocates memory which is not freed without
> SDL_Quit.
>
> You should do init once, before calling the main loop function.
>
> - Alon
>
>
>
> On Sun, Apr 6, 2014 at 4:43 PM, <[email protected] <javascript:>> wrote:
>
>>
>> <https://lh6.googleusercontent.com/-K5u_LGOXmLk/U0HjTLBYVtI/AAAAAAAAAAc/LJ-fIy-Rqo4/s1600/cannot+enlarge+memory.JPG>
>> Thanks for the help. I'm not sure if I really fixed the issue or just
>> created a more dominant one.
>> From running the new generated page I get* "Cannot enlarge memory
>> arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the
>> current value 16777216, (2) compile with ALLOW_MEMORY_GROWTH which adjusts
>> the size at runtime but prevents some optimizations, or (3) set
>> Module.TOTAL_MEMORY before the program runs."*
>>
>> Also, here's what my code looks like now.
>>
>>
>> #include <stdlib.h>
>>> #include <SDL/SDL.h>
>>> #include <emscripten.h>
>>>
>>> void renderStuff() {
>>> SDL_Init( SDL_INIT_VIDEO );
>>>
>>> SDL_Surface* bitmap = SDL_LoadBMP("bat.bmp");
>>> SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 0,
>>> SDL_HWSURFACE | SDL_DOUBLEBUF );
>>>
>>>
>>> // Part of the bitmap that we want to draw
>>> SDL_Rect source;
>>> source.x = 24;
>>> source.y = 63;
>>> source.w = 65;
>>> source.h = 44;
>>>
>>> // Part of the screen we want to draw the sprite to
>>> SDL_Rect destination;
>>> destination.x = 100;
>>> destination.y = 100;
>>> destination.w = 65;
>>> destination.h = 44;
>>>
>>> SDL_BlitSurface(bitmap, &source, screen, &destination);
>>>
>>> SDL_Flip(screen);
>>> }
>>>
>>> void one_iter() {
>>>
>>>
>>>
>>> SDL_Event event;
>>> bool gameRunning = true;
>>>
>>>
>>> if (SDL_PollEvent(&event))
>>> {
>>> if (event.type == SDL_QUIT)
>>> {
>>> gameRunning = false;
>>> }
>>> }
>>>
>>> renderStuff();
>>>
>>>
>>> }
>>>
>>> int main(int argc, char **argv)
>>> {
>>>
>>> emscripten_set_main_loop(one_iter, 60, 1);
>>>
>>> return 0;
>>> }
>>>
>>> Now, I imagine it's trying to take an unusual amount of memory for the
>> type of things it's intended to do but the browser won't let it so
>> everything runs good. However using the browser to fix my bug is obviously
>> the kind of thing that will backfire sooner or later. So now I'm wondering
>> what is causing it to attempt to take up more memory than it needs and if
>> the unresponsive script issue really went away or is just not able to
>> manifest on account of the newer issue.
>>
>>
>> On Sunday, April 6, 2014 1:56:33 PM UTC-5, Dave Nicponski wrote:
>>>
>>> I've not used SDL, but aren't you grabbing control of the event loop
>>> here in your while(gameRunning) { } loop? Each main loop invocation is
>>> happening in the browser's (single) UI thread. If you don't return control
>>> to the browser (by exiting the one_iter() function) then the browser will
>>> freeze.
>>>
>>> Maybe try structuring your code like this:
>>>
>>> void oneIter() {
>>> // Stuff currently inside your while() { } block
>>> if (!gameRunning) {
>>> // Stuff currently after your while() { } block, like SDLQuit() and
>>> friends
>>> }
>>> }
>>>
>>> int main() {
>>> // Setup code, stuff currently before your while() { } block
>>> emscripten_set_main_loop();
>>> }
>>>
>>>
>>> Now the oneIter() function will be invoked by the browser in a loop,
>>> yielding back to the browser each loop iteration.
>>>
>>> -dave-
>>>
>>> On Sunday, April 6, 2014 12:49:51 AM UTC-4, [email protected] wrote:
>>>>
>>>> <https://lh3.googleusercontent.com/-FrjglpaDPRs/U0DZZ1cTn9I/AAAAAAAAAAQ/29x4jM-0S_s/s1600/unresponsive%2Bscript3.JPG>
>>>> I'm currently trying to get this tutorial I've found
>>>> <http://www.aaroncox.net/tutorials/2dtutorials/sdlsprites.html>on SDL
>>>> to work with Emscripten but I think I might be running into problems with
>>>> the browser's event model:
>>>>
>>>> Here's the code:
>>>>
>>>> #include <SDL/SDL.h>
>>>>> #include <emscripten.h>
>>>>>
>>>>> const int WINDOW_WIDTH = 640;
>>>>> const int WINDOW_HEIGHT = 480;
>>>>> const char* WINDOW_TITLE = "SDL Start";
>>>>>
>>>>> void one_iter() {
>>>>> SDL_Init( SDL_INIT_VIDEO );
>>>>>
>>>>> SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH,
>>>>> WINDOW_HEIGHT, 0,
>>>>> SDL_HWSURFACE | SDL_DOUBLEBUF );
>>>>> SDL_WM_SetCaption( WINDOW_TITLE, 0 );
>>>>>
>>>>> SDL_Surface* bitmap = SDL_LoadBMP("bat.bmp");
>>>>>
>>>>> // Part of the bitmap that we want to draw
>>>>> SDL_Rect source;
>>>>> source.x = 24;
>>>>> source.y = 63;
>>>>> source.w = 65;
>>>>> source.h = 44;
>>>>>
>>>>> // Part of the screen we want to draw the sprite to
>>>>> SDL_Rect destination;
>>>>> destination.x = 100;
>>>>> destination.y = 100;
>>>>> destination.w = 65;
>>>>> destination.h = 44;
>>>>>
>>>>> SDL_Event event;
>>>>> bool gameRunning = true;
>>>>>
>>>>> while (gameRunning)
>>>>> {
>>>>> if (SDL_PollEvent(&event))
>>>>> {
>>>>> if (event.type == SDL_QUIT)
>>>>> {
>>>>> gameRunning = false;
>>>>> }
>>>>> }
>>>>>
>>>>> SDL_BlitSurface(bitmap, &source, screen, &destination);
>>>>>
>>>>> SDL_Flip(screen);
>>>>> }
>>>>>
>>>>> SDL_FreeSurface(bitmap);
>>>>>
>>>>> SDL_Quit();
>>>>> }
>>>>>
>>>>> int main(int argc, char **argv)
>>>>> {
>>>>> emscripten_set_main_loop(one_iter, 60, 1);
>>>>>
>>>>> return 0;
>>>>> }
>>>>>
>>>>
>>>>
>>>> I've read the Wiki on emscripten browser
>>>> environment<https://github.com/kripken/emscripten/wiki/Emscripten-browser-environment>so
>>>> I figured I had to use *emscripten_set_main_loop
>>>> *to make SDL_Quit() work and give control back to the browser and keep
>>>> it from freaking out. But as you can see it didn't work. Can anyone point
>>>> to me what I'm doing wrong? Any guidance here would be appreciated.
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.