BetaArchive Logo
Total Current Archive Size: 4765.54GB in 15409 files
Navigation Home Screenshots Image Uploader Server Info FTP Servers Wiki Forum RSS Feed Rules Please Donate
UP: 9d, 13h, 34m | CPU: 15% | MEM: 5854MB of 12279MB used
{The community for beta collectors}

Forum rules


Before you post, please make sure...

- ...you have first used Google to look for an answer, and you have asked other people you know via other methods (IM, e-mail, etc).
- ...your question has not been asked before. Search the forum first before posting.

If you meet those criteria, go ahead and post your question. Be sure to provide as much information you can about the problem and how to recreate it. Also provide information on hardware and software if applicable.


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPost subject: C# Stackoverflowexception was unhandled        Posted: Fri May 13, 2011 4:29 am 
Pro Beta Collector
Pro Beta Collector
User avatar
Offline

Joined
Fri Feb 12, 2010 3:52 am

Posts
339

Location
California, US

Favourite OS
4074
I get kept this error:

An unhandled exception of type 'System.StackOverflowException' occurred in Snake Game.exe

The line with the error is:

get { return SnakeRec; }

It is part of:

public Rectangle[] SnakeRec
{
get { return SnakeRec; }
}

Can anyone help me fix this error? Thanks

_________________
Image
Image

Last edited by No one on Zzz Dec 99, 3099 459:43 am, edited 0.1 times in total.


Top  Profile
 PostPost subject: Re: C# Stackoverflowexception was unhandled        Posted: Fri May 13, 2011 4:55 am 
Newbie Beta Collector
Newbie Beta Collector
Offline

Joined
Fri Apr 15, 2011 6:54 pm

Posts
20

Favourite OS
Longhorn 4074 or OS/2 Warp
Looks like a bit of an endless loop you have there. SnakeRec is property with it's get accessor basically returning itself over and over again till your app's stack space has been exhausted.

Perhaps inside get you should return a new instance of SnakeRec instead of how you're doing it there.


Top  Profile
 PostPost subject: Re: C# Stackoverflowexception was unhandled        Posted: Fri May 13, 2011 5:38 am 
Pro Beta Collector
Pro Beta Collector
User avatar
Offline

Joined
Fri Feb 12, 2010 3:52 am

Posts
339

Location
California, US

Favourite OS
4074
Can you tell me how to do that? Sorry, I"m new to c#, I've been using vb for quite a while.

_________________
Image
Image

Last edited by No one on Zzz Dec 99, 3099 459:43 am, edited 0.1 times in total.


Top  Profile
 PostPost subject: Re: C# Stackoverflowexception was unhandled        Posted: Fri May 13, 2011 5:57 am 
Newbie Beta Collector
Newbie Beta Collector
Offline

Joined
Fri Apr 15, 2011 6:54 pm

Posts
20

Favourite OS
Longhorn 4074 or OS/2 Warp
Ok..better idea.
In the code referencing "SnakeRec", create a new instance of the Rectangle struct and assign it to the property "SnakeRec"

http://msdn.microsoft.com/en-us/library ... angle.aspx << This shows what you'd need to do to do to create a new instance of rectangle, if you're not already familiar with that struct. If you are then just ignore this part :)

If SnakeRec doesn't have a "set" then one is needed for this to work. Basically that would like this:

private Rectangle[] rectVar;
public Rectangle[] SnakeRec
{
get { return rectVar; }
set { rectVar = value; }
}

define a variable above the struct....call it whatever you like, I'm going to use rectVar. Then change the "get" to return the new variable containing the instance that was provided in the "set".

I hope this makes sense.


Top  Profile
 PostPost subject: Re: C# Stackoverflowexception was unhandled        Posted: Fri May 13, 2011 8:40 pm 
Newbie Beta Collector
Newbie Beta Collector
Offline

Joined
Wed May 11, 2011 9:40 am

Posts
32

Location
Cairo, Egypt

Favourite OS
6.1.7601 SP 1
OK your problem here is you return the same variable as you have in the get.

public Rectangle[] SnakeRec
{
get { return SnakeRec; }
}

(Check the bolded red-colored text above) ... this cause infinite loop as rstat1 said ... you can overcome this by a simple way,

I guess you have a private Rectangle[] SnakeRec in side the class, you can convert it to be as follows:

private Rectangle[] _SnakeRec

and then:

public Rectangle[] SnakeRec
{
get { return _SnakeRec; }
}

This will definitely solve the problem ;)


Top  Profile
 PostPost subject: Re: C# Stackoverflowexception was unhandled        Posted: Sat May 14, 2011 4:25 am 
Pro Beta Collector
Pro Beta Collector
User avatar
Offline

Joined
Fri Feb 12, 2010 3:52 am

Posts
339

Location
California, US

Favourite OS
4074
sikas wrote:
OK your problem here is you return the same variable as you have in the get.

public Rectangle[] SnakeRec
{
get { return SnakeRec; }
}

(Check the bolded red-colored text above) ... this cause infinite loop as rstat1 said ... you can overcome this by a simple way,

I guess you have a private Rectangle[] SnakeRec in side the class, you can convert it to be as follows:

private Rectangle[] _SnakeRec

and then:

public Rectangle[] SnakeRec
{
get { return _SnakeRec; }
}

This will definitely solve the problem ;)


Thanks. This made me realize that what I was doing wrong.

_________________
Image
Image

Last edited by No one on Zzz Dec 99, 3099 459:43 am, edited 0.1 times in total.


Top  Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 




Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

All views expressed in these forums are those of the author and do not necessarily represent the views of the BetaArchive site owner.

Powered by phpBB® Forum Software © phpBB Group

Copyright © 2006-2013

 

Sitemap | XML | RSS