[waffle] [GSOC2014] Current design/implementation + the infamous corruption

Emil Velikov emil.l.velikov at gmail.com
Thu Jun 5 09:49:04 PDT 2014


On 05/06/14 03:19, Emil Velikov wrote:
> Hi all,
> 
> Over the last few days I have been though some head-scratching and re-writing
> things, in order to resolve an "interesting" memory corruption to no avail :'(
> 
> Before explaining more about the issue here is some info about the current
> design + where to get the patches. Let me know if you would like me to send
> them to the ML.
> 
> Branch GSOC2014 over at https://github.com/evelikov/waffle
> 
> Archlinux users can use the pkgbuild script in pkg/archlinux/mingw-w64-waffle.
> 
> Design by example - gl_sample.c (i.e. how to use waffle)
> 
> waffle_init()
> waffle_display_connect()
> + RegisterClass()        // Registers the window class used as a "template"
>                          // by Windows to create the window
> 
                           // Create a default/root window, config and context
                           // as wglGetProcAddress needs to be executed under
                           // current context.

Missed case:
waffle_get_proc_address()  // if (wglGetCurrentContext() == NULL) {
                           //     using_display_context = true;
                           //     wglMakeCurrent(display->hdc, display->hglrc)
                           // }
                           // ok = wglGetProcAddress()
                           // if (using_display_context == true)
                           //     wglMakeCurrent(NULL, NULL)
                           // return ok;

                           // Unbinding the current context may be an
                           // overkill although will help with unintentional
                           // misuse of waffle's API.

                           // NOTE: Will need to change waffle's internals
                           // in order to get access to wcore_display.
                           // The API will need a change to include the
                           // display waffle_get_proc_address(dpy, "glHam")


> waffle_config_choose(dpy...)
> + CreateWindow()         // Create a window and prepend it to the
>                          // wgl_display::windows list.
> 
Now that I look at it, I'm not entirely sure why I needed a list of all
windows in wgl_display. Seems like I can drop that.

> + ChoosePixelFormat()
> + SetPixelFormat()       // Set the pixelformat and link the current window
>                          // to the wgl_config
> 
> waffle_context_create(config...)
> + CreateContext(hDC... ) // At this point we need access to the wgl_window,
>                          // as hWnd/hDC (window_handle/device_context handle)
>                          // is essential.
>                          // This is where wgl_config::window comes into play.
> 
> waffle_window_create(config, w, h)
> + wgl_window_resize()    // Reuse the window, adjusting it's dimensions, as
>                          // w, h used at creation time are include the window
>                          // border. AFAICK there is no way to determine the
>                          // correct window dimensions prior to creation.
> 
> ...
> 
> waffle_window_create(config, w, h)
> + waffle_window_resize() // Reuse the window... and boom. Any suggestions on
>                          // how to resolve this, or should we mandate that
>                          // this is not a valid usage of waffle ?
> 
There is no use case in piglit + waffle{examples/utils} where one would create
multiple windows for a single config. I might just add a lovely assert and
don't worry about this too much.

With the above resolved I will take a look at handling gl profiles and alike.

> 
> And now back to the memory corruption:
> 
Resolved, thanks to Jon Turney.

The functions obtained by waffle_dl_sym() are part of the Windows API, which
uses different calling convention (stdcall vs cdecl) which causes the heap
corruption. Annotating properly makes the gl_basic test work like a charm.

AFAICS waffle_get_proc_address is in the same boat. Will need to test.

Cheers,
Emil


More information about the waffle mailing list