I spent some time looking through the RM, but was unable to find a section
detailing what is supposed to happen when dereferencing a dangling access.
My assumption is that it is erroneous behavior that may or may not result
into an exception since the access is not null but was deallocated after it
was copied to the return value in your example.

I would suggest you look wrapping the record data with more protection.
Some sort of protected action that prevents it from being deallocated until
the current operation is finished and detects if it has been deallocated
before performing an operation (and throwing an exception).  This way you
are in control of what happens.  You can catch the exception (which you
know will always occur since you coded it to do so) and handle it
gracefully.  This might mean that you cannot use it as an access type
directly, so it might require redesign.

On Mon, Jul 31, 2017 at 1:45 PM, Olivier Henley wrote:

> *Rebooting a question because I received no feedback; did original post a
> month ago.
>
> Using Gnoga for a multiplayer game, I have a question which I fail to
> answer myself because I do not know a) enough about Ada and b) enough about
> the architecture of Gnoga/Simple Components stack.
>
> - note1: A match is two players connected through webRTC.
> - note2: To establish a webRTC connection between those two players I have
> to relay some messages to one another, without delay.
>
> This sample code is a subset of what I have done to relay messages from
> one player to the other. My question is about the eventual outcome of one
> player disconnecting while Relaying. Let suppose the 'other' player is
> killing its browser.
> ----------------------------
>
> procedure Relay_Signal (App_Data : in App_Data_Access; Value : String) is
>       Other_App_Data : App_Data_Access := Control.Find_Other(App_Data);
> begin
>       if Other_App_Data /= null then
>          My_Game.Controller.Relay_Message(Other_App_Data, Value);
>       end if;
> end Relay_Signal;
>
> protected Control is
>       function Find_Other (App_Data : App_Data_Access) return
> App_Data_Access;
> private
>       Matchs : Matchs_Vec.Vector;
> end Control;
>
> protected body Control is
>
>       function Find_Other (App_Data : App_Data_Access) return
> App_Data_Access is
>       begin
>          if App_Data.Match_Index_Is_Valid then
>             for Player of Matchs.Element(App_Data.Match_Index).Players
> loop
>                if Player /= App_Data then
>                   return Player;
>                end if;
>             end loop;
>          end if;
>          return null;
>       end Find_Other;
>
> end Control;
>
> -----------------------------
>
> I suppose that in the worst case: Other_App_Data is found and returned
> from Find_Other but that other player is disconnected (Other_App_Data
> becomes invalid) just before My_Game.Controller.Relay_Message(Other_App_Data,
> Value) is called. What I think will happen is just an exception thrown when
> I am manipulating Other_App_Data inside Relay_Message.
>
> 1) Am I right? If so is it OK?
> 2) Else, why and how should I handle such a case?
>
> Thx,
>
> Olivier
> <https://lists.sourceforge.net/lists/listinfo/gnoga-list>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gnoga-list mailing list
Gnoga-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gnoga-list

Reply via email to