-
Notifications
You must be signed in to change notification settings - Fork 30
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
Possible race condition with MessageBox #49
Comments
I trimmed down your example a bit further, see the end of this message. It's a bit difficult to reproduce here but something is indeed racy I don't have time to investigate this further at the moment. Could you please create an equivalent C program to make sure the bug is not on SDL's side. The full bt is:
(* compile with ocamlfind ocamlopt -package tsdl -linkpkg -thread main.ml *)
open Tsdl
let log_err fmt = Format.eprintf (fmt ^^ "@.")
let close_message_box () =
let d =
let open Sdl.Message_box in
let action =
{ button_flags = button_returnkey_default;
button_id = 1; button_text = "Save then quit" }
in
let cancel =
{ button_flags = button_escapekey_default;
button_id = 3; button_text = "Cancel" }
in
let color_scheme =
{ color_background = (255, 255, 255);
color_text = (255, 0, 0);
color_button_border = (0, 255, 0);
color_button_background = (0, 0, 255);
color_button_selected = (0, 255, 255) }
in
{ flags = warning; window = None; title = "Action";
message = "Do you want to action ?"; buttons = [cancel; action];
color_scheme = Some color_scheme }
in
Sdl.show_message_box d
let event_loop () =
let keycode e = Sdl.Event.(get e keyboard_keycode) in
let e = Sdl.Event.create () in
let rec loop () = match Sdl.wait_event (Some e) with
| Error (`Msg e) -> log_err " Could not wait event: %s" e; 1
| Ok () ->
match Sdl.Event.(enum (get e typ)) with
| `Quit -> 0
| `Key_down when keycode e = Sdl.K.escape ->
begin match close_message_box () with
| Error (`Msg e) -> log_err "Could not show message box: %s" e; 1
| Ok 1 -> 0
| _ -> loop ()
end
| _ -> loop ()
in
loop ()
let main () = match Sdl.init Sdl.Init.(video + events) with
| Error (`Msg e) -> log_err "Could not init SDL: %s" e; exit 1
| Ok () ->
let ret = event_loop () in
Sdl.quit ();
exit ret
let () = main () |
I failed to reproduce the bug using the following C example. // Compile with:
// cc main.c `sdl2-config --libs --cflags` -Wall -Wextra
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <SDL.h>
int message()
{
const SDL_MessageBoxButtonData buttons[] = {
{ 0, 0, "Nothing" },
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "Return (quit)" },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 2, "Escape" },
};
const SDL_MessageBoxColorScheme colorScheme = {
{
{ 255, 0, 0 },
{ 0, 255, 0 },
{ 255, 255, 0 },
{ 0, 0, 255 },
{ 255, 0, 255 }
}
};
const SDL_MessageBoxData messageboxdata = {
SDL_MESSAGEBOX_INFORMATION,
NULL,
"example message box",
"select a button",
SDL_arraysize(buttons),
buttons,
&colorScheme
};
int buttonid;
if (SDL_ShowMessageBox(&messageboxdata, &buttonid) < 0) {
SDL_Log("error displaying message box");
exit(1);
return 1;
}
if (buttonid == -1)
SDL_Log("no selection");
else
SDL_Log("selection was %s", buttons[buttonid].text);
return (buttonid == 1);
}
int main(void)
{
SDL_Window *win;
SDL_Surface *screen;
SDL_Event e;
SDL_Init(SDL_INIT_VIDEO);
win = SDL_CreateWindow("SDL",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480, 0);
screen = SDL_GetWindowSurface(win);
SDL_FillRect(screen, NULL, 0);
SDL_UpdateWindowSurface(win);
while (1)
{
if (SDL_WaitEvent(&e))
{
if (e.type == SDL_QUIT)
break;
if (e.type == SDL_KEYDOWN
&& e.key.keysym.sym == SDLK_ESCAPE)
{
if (message())
break;
}
}
}
SDL_DestroyWindow(win);
SDL_Quit();
} |
@sguillia thanks for the C program. I think you can close the report upstream as this seems to be on our side. I need to recheck what we are doing here but I don't have According to the backtrace it seems that the pointer of the |
So in 595d8a5 I tried to add a little bit of logging by attaching a finalizer on the struct that is given to the C function. It seems that structures are not freed for quite sometime and then a hundred of them is freed after around @yallop do you think this could be a problem in If you want to have a look this can be tried with the OCaml program in this message and:
|
I'm not sure. I'll aim to dig into this later this week. |
Things have become very busy here, and unfortunately it's going to be a little while longer before I can investigate this. But I think your suspicion about the lifetime of the |
While writing an application using OCaml and Tsdl, I encountered a bug which affects either Tsdl, SDL, Cocoa or Ocaml bindings.
I fully described the bug here:
https://bugzilla.libsdl.org/show_bug.cgi?id=4069
In short, the app crashes (sigabort or segfault) when repeatedly opening dialogs for 30 seconds.
Could you please take a look at it?
The text was updated successfully, but these errors were encountered: