C stack overflow

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

C stack overflow

Geoffrey Hug
Hi all, I'm getting a strange problem that has now been driving me crazy for a day and a half. I keep getting a "C stack overflow" error that apparently comes from a bad instance reference ( I guess ).

This is the code of my class that I want to send to my server class :

class ClientApi extends haxe.remoting.AsyncProxy<IGameClient> {}

class PlayerServer implements IPlayerServer
{
    var clientApi : ClientApi;
    var id : Int;
    var name : String;
    var socketConnection : haxe.remoting.SocketConnection;
    public var lang : String;
    public var room : Room;
    public var img : String;
    public var isActive : Bool;
    public var score : Int;
    public static var playgroundW : Int = 0;
    public static var playgroundH : Int = 0;
    public static var currentId : Int = 0;
    var startTime : Float;
    var connectTime : Float;

    public function new( scnx : haxe.remoting.SocketConnection )
    {
        clientApi = new ClientApi( scnx.client );
        (cast scnx).__private = this;
        socketConnection = scnx;
        id = currentId;
        currentId++;
        img = "defaultPlayer.png";
        score = 0;
        isActive = false;

    }

    public function identify( text : String, image : String, language : String )
    {
        if( this.name == null )
        {   
            trace( text + " : " + image + " " + language );
            this.name = text;
            this.img = image;
            this.lang = language;       
               
           
            FruttiServer.join( this );           
           
        }
       
    }

The weird thing here is if I trace "this" in my new() function it displays fine but when I try to trace it in the identify() function there are a lot of exceptions. Also, I can trace some vars but the clientApi throws errors.

I get a "C stack overflow" error on the call to FruttiServer.join( this) if I surround it with try catch

I just don't get it... And the "C stack overflow" message really isn't helping at all.

Anyone can tell me what's wrong or what this message means ?




--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C stack overflow

laurence taylor
The message refers to the collection of references (the stack) that a runtime (nekovm)  keeps, and is usually the result excessive or unintended recursion, where each time a function calls itself it pushes the references that it has to the stack for later use, and cannot let got of them because the function has not yet returned, until such a point as the vm runs out of  allocated space.

You will probably find there are two references a -> b and b -> a, and if you want to represent one, it will ask for the representation of the other, which will in turn ask for the representation of the first, and so on. This may be an error in the toString() function or (less likely) an issue with serialization. 

A leaf is the terminating node of a tree structure, and if you are drilling down into data, you need to null check before using a reference. 

this.b.c 

will throw an error if b is null, you should find that somewhere.

I hope that clears things up.

regards,
Laurence
On Tue, Aug 2, 2011 at 12:10 PM, Geoffrey Hug <[hidden email]> wrote:
Hi all, I'm getting a strange problem that has now been driving me crazy for a day and a half. I keep getting a "C stack overflow" error that apparently comes from a bad instance reference ( I guess ).

This is the code of my class that I want to send to my server class :

class ClientApi extends haxe.remoting.AsyncProxy<IGameClient> {}

class PlayerServer implements IPlayerServer
{
    var clientApi : ClientApi;
    var id : Int;
    var name : String;
    var socketConnection : haxe.remoting.SocketConnection;
    public var lang : String;
    public var room : Room;
    public var img : String;
    public var isActive : Bool;
    public var score : Int;
    public static var playgroundW : Int = 0;
    public static var playgroundH : Int = 0;
    public static var currentId : Int = 0;
    var startTime : Float;
    var connectTime : Float;

    public function new( scnx : haxe.remoting.SocketConnection )
    {
        clientApi = new ClientApi( scnx.client );
        (cast scnx).__private = this;
        socketConnection = scnx;
        id = currentId;
        currentId++;
        img = "defaultPlayer.png";
        score = 0;
        isActive = false;

    }

    public function identify( text : String, image : String, language : String )
    {
        if( this.name == null )
        {   
            trace( text + " : " + image + " " + language );
            this.name = text;
            this.img = image;
            this.lang = language;       
               
           
            FruttiServer.join( this );           
           
        }
       
    }

The weird thing here is if I trace "this" in my new() function it displays fine but when I try to trace it in the identify() function there are a lot of exceptions. Also, I can trace some vars but the clientApi throws errors.

I get a "C stack overflow" error on the call to FruttiServer.join( this) if I surround it with try catch

I just don't get it... And the "C stack overflow" message really isn't helping at all.

Anyone can tell me what's wrong or what this message means ?




--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C stack overflow

Johann Borck
In reply to this post by Geoffrey Hug
On 08/02/2011 12:10 PM, Geoffrey Hug wrote:
> Hi all, I'm getting a strange problem that has now been driving me crazy for a day and a half. I
> keep getting a "C stack overflow" error that apparently comes from a bad instance reference ( I
> guess ).
>
Did you mention on which platform/target you are getting this error? I didn't see it, but I may have
overlooked something.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C stack overflow

Geoffrey Hug
No I forgot It's neko, I have a client/server application with a neko server and flash 9 clients

2011/8/2 Johann Borck <[hidden email]>
On 08/02/2011 12:10 PM, Geoffrey Hug wrote:
Hi all, I'm getting a strange problem that has now been driving me crazy for a day and a half. I keep getting a "C stack overflow" error that apparently comes from a bad instance reference ( I guess ).

Did you mention on which platform/target you are getting this error? I didn't see it, but I may have overlooked something.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C stack overflow

Geoffrey Hug


Thank you Laurence for your explanation I think I understand it way better now even though I'm not sure what exactly causes it.

Anyway this started happening after I added hashes to store lists. I have a Hash that contains Lists of Room objects, these Room objects have an attribute that is a PlayerServer list.

So the Hash stores lists of Rooms in keys that are the different languages that a player could speak. And then the Room must contain the players in it in a list.

To know where my player should enter I use it's language attribute so i can do a hash.get( language ).last().add( playerServer ) or if no room available, hash.get(language).add( new Room( playerServer ) )

My room object is created with a PlayerServer in parameter because I create a Room when a player joins and he needs a new room only.

So I'm guessing it must be something in this part of code that causes it.

To help with clarity, this is the code I just described :


public static function join( plS : PlayerServer )
{
       
        if( plS.room == null )
        {
            if( rooms.get(plS.lang).length > 0 && rooms.get(plS.lang).last().players.length < 4 && !rooms.get(plS.lang).last().gameLaunched )
            {
                    plS.room = rooms.get(plS.lang).last();
                    rooms.get(plS.lang).last().players.add( plS );
            }
            else
            {

                    var newRoom = new Room( plS );                   
                    rooms.get(plS.lang).add( newRoom );                   
                    plS.room = newRoom;
             }
             
        
         }
       
  
            plS.notifyJoin();
}

I hope this is not too confused.

So I'm going to look into this part but I'll be glad if anyone sees the problem already :)


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C stack overflow

Jan_Flanders
In reply to this post by Geoffrey Hug
On Tue, Aug 2, 2011 at 2:29 PM, Geoffrey Hug <[hidden email]> wrote:
No I forgot It's neko,
In that case you may have an overflow due to the 31 bits Ints in neko.

http://www.google.com/search?q=neko+31+bits
http://haxe.org/api/haxe/int32

Jan

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: C stack overflow

Geoffrey Hug
In reply to this post by Geoffrey Hug
Got it ! It was because I was calling the Room constructor with my PlayerServer as parameter.

Not sure what was happening but I made the parameter optionnal and by creating a new Room() I was able to make it work fine.

I still would like to understand why this would make it crash because I don't see any reason that this would lead to a loop. :/





--
haXe - an open source web programming language
http://haxe.org