Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Support SDL_SetWindowTitle() by setting document.title. #6

Merged
merged 1 commit into from
Feb 21, 2015
Merged

Support SDL_SetWindowTitle() by setting document.title. #6

merged 1 commit into from
Feb 21, 2015

Conversation

dreamlayers
Copy link
Contributor

DOSBox shows some information via the title, which is currently going nowhere. This modification will change the HTML page title.

I wonder if people hosting Emscripten generated code will see title changing as undesirable?

@juj
Copy link
Contributor

juj commented Feb 4, 2015

I like this! A lot of pages change the window title, I don't see any reason why this wouldn't be appropriate here as well. What do you think @kripken ?

@kripken
Copy link
Member

kripken commented Feb 5, 2015

I suppose the argument could be made that there might be more than one app on a page; the "title" should be on top of the canvas, in a sense, but not necessarily the whole page. But, probably the majority of cases are going to be singleton canvases, so it would be ok...

The bigger question for me is, does this change anything right now? That is, if the user doesn't explicitly call a method to change the title, does SDL2 set it to "SDL2 Application" or something other default? If so this is a surprise we should avoid, otherwise, let's merge this.

@dreamlayers
Copy link
Contributor Author

SDL 2 does not set a default window title. If the title parameter to SDL_CreateWindow() is NULL, then SDL_SetWindowTitle() is not called. The only other place it could be called is SDL_RecreateWindow(), where it is only called if title was set for the previous window. This is all in src/video/SDL_video.c. Only other occurrences of SetWindowTitle are in declarations in header files and code in specific video drivers.

@dreamlayers
Copy link
Contributor Author

What about adding a function to Module which is called to set the title? Then it could be set externally, overriding the default title-changing behaviour.

@jbaicoianu
Copy link

I'm actually working on a case which uses multiple SDL apps in one page now. It would be nice to be able to get the title out of the app, but setting it directly on document.title might be a problem.

Maybe if there's an optional callback you can set in module args when instantiating the app, windowtitle: function(txt) { ... }, or maybe the app could fire events that can be handled by the controlling page if custom behavior is needed?

@kripken
Copy link
Member

kripken commented Feb 9, 2015

I agree that an option on Module sounds like the best solution. Then multiple apps on one page would work. And we could make the default set the document title, of course, in the default HTML shell definition of Module.

If Module.setWindowTitle isn't defined, we'd either do nothing or warn, not sure which is best. Warn perhaps.

@dreamlayers
Copy link
Contributor Author

What about setting setWindowTitle if it's undefined? So, if someone wants to override it, they can at any time, but if they do nothing it will be there and work. This would be done at some point during startup. I'm not sure what's the best place.

if (typeof(Module['setWindowTitle']) == 'undefined')
    Module['setWindowTitle'] = function(title) { document.title = title };

@kripken
Copy link
Member

kripken commented Feb 9, 2015

Sounds reasonable. shell.js in the ENVIRONMENT_IS_WEB section, where we fill in other Module stuff as needed, is the right place.

The code here should then check and do nothing if it is not defined.

@dreamlayers
Copy link
Contributor Author

I have created emscripten-core/emscripten#3192 and updated this pull request with code using Module['setWindowTitle']().

static void
Emscripten_SetWindowTitle(_THIS, SDL_Window * window) {
EM_ASM_INT({
if (typeof Module['setWindowTitle'] != 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict comparison here (!==)

kripken added a commit that referenced this pull request Feb 21, 2015
Support SDL_SetWindowTitle() by setting document.title.
@kripken kripken merged commit b930f9a into emscripten-ports:master Feb 21, 2015
@dreamlayers dreamlayers deleted the set-window-title branch February 21, 2015 22:46
Daft-Freak pushed a commit that referenced this pull request Oct 20, 2016
Robert Folland

When running this little test program with SDL2 on Wayland it often crashes in SDL_Init.

From a backtrace it is apparent that there is a race condition in creating a xkb_context_ref. Sometimes it is 0x0.

By moving the relevant lines higher up in Wayland_VideoInit (in SDL2-2.0.4/src/video/wayland/SDL_waylandvideo.c:302) this seems to get fixed.

I moved the call to WAYLAND_xkb_context_new() up to before the call to WAYLAND_wl_display_connect().

Here is the test program (just a loop of init and quit), and a backtrace from gdb:

#include <cstdio>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <unistd.h>
#include <iostream>

int main(int argc, char **argv)
{
    int count = atoi(argv[1]);

    for (int i = 0; i < count; i++) {
        std::cout << "Init " << i << std::endl;
        if (SDL_Init(SDL_INIT_VIDEO) < 0) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
                         "Couldn't initialize SDL: %s\n",
                         SDL_GetError());
            return 1;
        }
        std::cout << "Quit" << std::endl;
        SDL_Quit();
    }
    return 0;
}


Init 12
Quit
Init 13

Program received signal SIGSEGV, Segmentation fault.
xkb_context_ref (ctx=ctx@entry=0x0) at src/context.c:156
156         ctx->refcnt++;
(gdb) bt
#0  xkb_context_ref (ctx=ctx@entry=0x0) at src/context.c:156
#1  0x00007ffff5e1cd4c in xkb_keymap_new (ctx=0x0, format=XKB_KEYMAP_FORMAT_TEXT_V1, flags=flags@entry=XKB_KEYMAP_COMPILE_NO_FLAGS) at src/keymap-priv.c:65
#2  0x00007ffff5e1c6cc in xkb_keymap_new_from_buffer (ctx=<optimized out>,
    buffer=0x7ffff7fd5000 "xkb_keymap {\nxkb_keycodes \"(unnamed)\" {\n\tminimum = 8;\n\tmaximum = 255;\n\t<ESC>", ' ' <repeats 16 times>, "= 9;\n\t<AE01>", ' ' <re
peats 15 times>, "= 10;\n\t<AE02>", ' ' <repeats 15 times>, "= 11;\n\t<AE03>", ' ' <repeats 15 times>, "= 12;\n\t<AE04>", ' ' <repeats 12 times>..., length=48090,
    format=<optimized out>, flags=<optimized out>) at src/keymap.c:191
#3  0x00007ffff7b8ea4e in keyboard_handle_keymap (data=0x6169b0, keyboard=<optimized out>, format=<optimized out>, fd=5, size=48091)
    at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/wayland/SDL_waylandevents.c:269
#4  0x00007ffff64501f0 in ffi_call_unix64 () from /usr/lib/libffi.so.6
#5  0x00007ffff644fc58 in ffi_call () from /usr/lib/libffi.so.6
#6  0x00007ffff665be3e in wl_closure_invoke (closure=closure@entry=0x61f000, flags=flags@entry=1, target=<optimized out>, target@entry=0x616d20,
    opcode=opcode@entry=0, data=<optimized out>) at src/connection.c:949
#7  0x00007ffff6658be0 in dispatch_event (display=<optimized out>, queue=<optimized out>) at src/wayland-client.c:1274
#8  0x00007ffff6659db4 in dispatch_queue (queue=0x617398, display=0x6172d0) at src/wayland-client.c:1420
#9  wl_display_dispatch_queue_pending (display=0x6172d0, queue=0x617398) at src/wayland-client.c:1662
#10 0x00007ffff665a0cf in wl_display_roundtrip_queue (display=0x6172d0, queue=0x617398) at src/wayland-client.c:1085
#11 0x00007ffff7b8faa0 in Wayland_VideoInit (_this=<optimized out>) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/wayland/SDL_waylandvideo.c:302
#12 0x00007ffff7b7aed6 in SDL_VideoInit_REAL (driver_name=<optimized out>, driver_name@entry=0x0) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/video/SDL_video.c:513
#13 0x00007ffff7ae0ee7 in SDL_InitSubSystem_REAL (flags=16416) at /home/vlab/abs/sdl2/src/SDL2-2.0.4/src/SDL.c:173
#14 0x0000000000400b24 in main (argc=2, argv=0x7fffffffebb8) at vplay-init.cpp:13
(gdb)
Daft-Freak pushed a commit that referenced this pull request May 7, 2021
Make sure the thread is actually paused, and context backep-up, before
SurfaceView is destroyed (eg surfaceDestroyed() actually returns).

Add a timeout when surfaceDestroyed() is called, and check 'backup_done' variable.

It prevents crashes like:

  #00  pc 000000000000c0d0  /system/lib64/libutils.so (android::RefBase::incStrong(void const*) const+8)
  #1  pc 000000000000c7f4  /vendor/lib64/egl/eglSubDriverAndroid.so (EglAndroidWindowSurface::UpdateBufferList(ANativeWindowBuffer*)+284)
  #2  pc 000000000000c390  /vendor/lib64/egl/eglSubDriverAndroid.so (EglAndroidWindowSurface::DequeueBuffer()+240)
  #3  pc 000000000000bb10  /vendor/lib64/egl/eglSubDriverAndroid.so (EglAndroidWindowSurface::GetBuffer(EglSubResource*, EglMemoryDesc*)+64)
  #4  pc 000000000032732c  /vendor/lib64/egl/libGLESv2_adreno.so (EglWindowSurface::UpdateResource(EsxContext*)+116)
  #5  pc 0000000000326dd0  /vendor/lib64/egl/libGLESv2_adreno.so (EglWindowSurface::GetResource(EsxContext*, EsxResource**, EsxResource**, int)+56)
  #6  pc 00000000002ae484  /vendor/lib64/egl/libGLESv2_adreno.so (EsxContext::AcquireBackBuffer(int)+364)
  #7  pc 0000000000249680  /vendor/lib64/egl/libGLESv2_adreno.so (EsxContext::Clear(unsigned int, unsigned int, unsigned int, EsxClearValues*)+1800)
  #8  pc 00000000002cb52c  /vendor/lib64/egl/libGLESv2_adreno.so (EsxGlApiParamValidate::GlClear(EsxDispatch*, unsigned int)+132)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants