Segment Fault.

Monkey Forums/Monkey Programming/Segment Fault.

Paul - Taiphoz(Posted 2012) [#1]
Have one right now, got no clue why, changed very little since my last compile and test, but enough to not be sure what line's are at fault.

Any suggestions ? this error needs to give a line number or summit, its bloody painful.


bruZard(Posted 2012) [#2]
i've got a little black box and i can't open it, any idea why?

thats the way i've read your post.

What you're try to compile? what you're try to do? whats the problem?


muddy_shoes(Posted 2012) [#3]
What target?
When you compile or when you run?
If you have an error message, post the actual error message.
If your code isn't multiple files then post the code in some codebox tags.


dawlane(Posted 2012) [#4]
What target? And post some code please?
Debugging Monkey can be a pain. It tuck me an hour to figure out why some code ran all right on Flash/HMTL5 but crashed on glfw. Turned out that Monkey didn't like me using Loadstate in a certain way if there was no previous saved state.
'Chokes an dies
Local s:String = Loadstate()
If s = "" Then blah..

'Works
If Loadstate() = "" Then blah...



Floyd(Posted 2012) [#5]
It's an out of range array index.

That's a guess, of course, based on the recent discussion of Monkey arrays.


[monkeycode]Print X <= Y[/monkeycode]
[monkeycode]Print X >= Y[/monkeycode]
[monkeycode]Print X =< Y[/monkeycode]
[monkeycode]Print X => Y[/monkeycode]
[monkeycode]Print X >< Y[/monkeycode]
[monkeycode]Print X <> Y[/monkeycode]


dawlane(Posted 2012) [#6]
It's an out of range array index.

That's a guess, of course, based on the recent discussion of Monkey arrays.
I though Monkey in debug mode trapped those?


ziggy(Posted 2012) [#7]
Depending on target, you may have some additional info on the console window of the IDE.


Paul - Taiphoz(Posted 2012) [#8]
Well I was vague because the bloody code would not really give me a hint as to what part of the code was causing the issue, I could hardly dump the full project on the forum.

It's this line.

		If KeyDown(KEY_DOWN) 
			GameStage.offsety-=20
			'bound checking, this is for debug only.
			'If GameStage.offsety<=GameStage.offmin Then GameStage.offsety=GameStage.offmin
			'If GameStage.offsety>=GameStage.offmax Then GameStage.offsety=GameStage.offmax			
		End If


I had to comment them both out, GameStage is a clevel , a class I made to hold level info , and the offset's are the position the player is on the level, well to be more specific the amount I adjust the level to display the right tiles under the player.

The GameStage class is in another file from the file that these lines come from, if you follow me, so I think it's goto be a scope issue, but since I called it with GameStage. should that not cover the scope. ?

in my level.monkey file I have this at the top.

Global GameStage:= New clevel


Paul - Taiphoz(Posted 2012) [#9]
Oh and is all the Output window had which is why I didnt post it.

Translating iTerm
E:/Code/MonkeyPro/MoneyPro52f/bin/trans_winnt -target=html5 -run E:/Source/Monkey/Invaders/iTerm.monkey

TRANS monkey compiler V1.29
Parsing...
Semanting...
Monkey runtime error: Segmentation violation



Process Complete



Paul - Taiphoz(Posted 2012) [#10]
I dont get why the IF Statements, cause this problem but the line above which talks to the same class and variable does not.


dawlane(Posted 2012) [#11]
See what happens if you use locals vars.


muddy_shoes(Posted 2012) [#12]
So, it's when you're compiling, not running. That's kind of important.

It looks like a Monkey bug. Can you post your "clevel" class definition?


Paul - Taiphoz(Posted 2012) [#13]
I tracked it down, I guess I was doing something a bit monkeynoob.

Class clevel
	Field StageWidth:Int=5
	Field StageLength:Int=100
	Field stage:Int
	Field grid:Int[500] 	
	Field offsetx:Float=64
	Field offsety:Float=0

	Field offmax:int = (self.StageLenght * 128)-864

	'Field offmax:Int = (100*128)-864


I Guess that at that point in the execution self.StageLength isnt seyup ? the commented line bellow is what works..

You would think that the compiler would catch that a bit better rather than giving me some obscure error.


muddy_shoes(Posted 2012) [#14]
StageLength <> StageLenght, but that's by the by as the Monkey compiler shouldn't crash no matter what the input.

Edit: Apparently the "self." causes Monkey's compiler to not check whether the identifier is valid at all.


therevills(Posted 2012) [#15]
I would say its both a Monkey bug and a user error :P

Simple code sample to show the error:
Function Main:Int()
	New TestClass()
	Return 0
End

Class TestClass
	Field a% = 100
	Field b% = Self.a + 10
	
	Method New()
		Print a
		Print b
	End
End


I'll raise it in the Monkey bug forum...

http://www.monkeycoder.co.nz/Community/posts.php?topic=2259


Paul - Taiphoz(Posted 2012) [#16]
Yeah knew something had to be up with that, as for user error lol. par for the course with me, if there is a wrong way to do it or a bug in the code im gona find it.


muddy_shoes(Posted 2012) [#17]
I'm sorry but this is in no way an example of a "user error". If Monkey worked properly in this instance the user would have received an error stating that the identifier couldn't be found and then one stating that it couldn't be "accessed from here" when they corrected the spelling(which is a poor message but at least something).

Code errors should never cause the compilation process to simply fall over.


Paul - Taiphoz(Posted 2012) [#18]
Yeah, lol what he said . see wasnt my fault after all :P

/me runs off.


dawlane(Posted 2012) [#19]
Code errors should never cause the compilation process to simply fall over.
True. But at least TRANS V1.29 gives you a message, TRANS V1.27 just chokes and gives you and gives you the "This program has stop working" dialog box.

Compiling therevills sample with stdcpp using TRANS V1.27 gives me this in the console window of Jungle.

ERROR:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
ERROR:terminate called after throwing an instance of 'char const*'
Abnormal program termination. Exit code: 3


Paul - Taiphoz(Posted 2012) [#20]
yeah rofl the debug cycle needs a lot of work, thankfully tho and only a few days in with Pro, i'v not hit to many brick walls, and my code base on this project is growing daily so touch wood, its all moving along.


dawlane(Posted 2012) [#21]
Depending on how I'm going to use a class. I tend to over ride the default new method to initialize it ( or a static function and return the type ) rather the initialisation in the fields.

EDIT: You asked this in another thread
Whats the most sprites you have used with monkey so far ? because people in other threads have been talking about how the more draw commands you use in a loop the slower your code gets, because of something to do with it using another image or memory block or summit I forget to be honest lol, maby some one can post and explain it better than me.
I'm surprised that Samah didn't point you to this. Post 4 onwards.


muddy_shoes(Posted 2012) [#22]
ERROR:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


I'd say that was more helpful than "Monkey runtime error: Segmentation violation". At least it flags to the user that it's a problem that they should raise with the application developers (although it's not always obvious who they are).

If the monkey error had said something along the lines of "Hey, this shouldn't happen! Let BRL know about it!" this entire thread probably wouldn't exist. Even better is to add a remote report facility to the error trapping. It's not a major effort to do so and it both increases the number of faults you hear about and raises the quality of those reports so you can actually fix them.