aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/wx/src/wxe_server.erl22
-rw-r--r--lib/wx/test/wx_xtra_SUITE.erl16
2 files changed, 24 insertions, 14 deletions
diff --git a/lib/wx/src/wxe_server.erl b/lib/wx/src/wxe_server.erl
index 45184a3bc8..04e0d0faf4 100644
--- a/lib/wx/src/wxe_server.erl
+++ b/lib/wx/src/wxe_server.erl
@@ -118,8 +118,8 @@ handle_call({disconnect_cb,Obj,Msg},{From,_},State) ->
handle_call(stop,{_From,_},State = #state{users=Users0, cleaners=Cs0}) ->
Env = get(?WXE_IDENTIFIER),
Users = gb_trees:to_list(Users0),
- Cs = lists:map(fun({Pid,User}) ->
- spawn_link(fun() -> cleanup(Env,Pid,[User]) end)
+ Cs = lists:map(fun({_Pid,User}) ->
+ spawn_link(fun() -> cleanup(Env,[User], false) end)
end, Users),
{noreply, State#state{users=gb_trees:empty(), cleaners=Cs ++ Cs0}};
@@ -179,9 +179,12 @@ handle_info({'DOWN',_,process,Pid,_}, State=#state{users=Users0,cleaners=Cs}) ->
Env = wx:get_env(),
case User of
#user{events=[], evt_handler=undefined} -> %% No need to spawn
- {noreply, State#state{users=Users,cleaners=Cs}};
+ case Cs =:= [] andalso gb_trees:is_empty(Users) of
+ true -> {stop, normal, State#state{cleaners=Cs}};
+ false -> {noreply, State#state{users=Users,cleaners=Cs}}
+ end;
_ ->
- Cleaner = spawn_link(fun() -> cleanup(Env,Pid,[User]) end),
+ Cleaner = spawn_link(fun() -> cleanup(Env,[User],true) end),
{noreply, State#state{users=Users,cleaners=[Cleaner|Cs]}}
end
catch _E:_R ->
@@ -427,15 +430,18 @@ find_handler([],_Object,_Fun,Res) ->
%% The server handles callbacks from driver so every other wx call must
%% be called from another process, therefore the cleaning must be spawned.
%%
-cleanup(Env, _Pid, Data) ->
+%% Using Disconnect when we terminate can crash, it is timing releated
+%% but it seems that disconnect on windows that are being deleted are bad.
+%% Since we are terminating the data will be cleaned up anyway.
+cleanup(Env, Data, Disconnect) ->
put(?WXE_IDENTIFIER, Env),
- lists:foreach(fun cleanup/1, Data),
+ lists:foreach(fun(User) -> cleanup(User, Disconnect) end, Data),
gen_server:cast(Env#wx_env.sv, {cleaned, self()}),
normal.
-cleanup(#user{events=Evs, evt_handler=Handler}) ->
+cleanup(#user{events=Evs, evt_handler=Handler}, Disconnect) ->
lists:foreach(fun(#event{object=O, callback=CB, cb_handler=CbH}) ->
- catch wxEvtHandler:disconnect_impl(CbH,O),
+ Disconnect andalso (catch wxEvtHandler:disconnect_impl(CbH,O)),
case is_function(CB) of
true ->
wxEvtHandler:destroy_evt_listener(CbH);
diff --git a/lib/wx/test/wx_xtra_SUITE.erl b/lib/wx/test/wx_xtra_SUITE.erl
index a2d4c26319..8d5d7ddb6a 100644
--- a/lib/wx/test/wx_xtra_SUITE.erl
+++ b/lib/wx/test/wx_xtra_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -129,15 +129,19 @@ app_dies(_Config) ->
app_dies2(Test, N) ->
spawn_link(fun() -> Test(N) end),
- receive
- {'EXIT', _, {oops, last}} -> ok;
- {'EXIT', _, {oops, _}} -> app_dies2(Test, N+1)
+ receive
+ {'EXIT', _, {oops, Server, What}} ->
+ Ref = erlang:monitor(process, Server),
+ receive {'DOWN', Ref, _, _, _} -> ok end,
+ timer:sleep(100),
+ What =/= last andalso app_dies2(Test, N+1)
end.
oops(Die, Line) when (Die =:= last) orelse (Die =< Line) ->
- timer:sleep(300),
+ timer:sleep(200),
?log(" Exits at line ~p~n",[Line]),
- exit({oops, Die});
+ Server = element(3, wx:get_env()),
+ exit({oops, Server, Die});
oops(_,_) -> ok.