Freeze Problem with Save Function?

Blitz3D Forums/Blitz3D Programming/Freeze Problem with Save Function?

Guy Fawkes(Posted 2012) [#1]
Hi all. My Save Function for some reason is freezing, and IDK why... I import a file, THEN load a file, it loads the level fine. NOW HERE's where I have a problem. For SOME reason, when I go to save the level for the 2nd time, it freezes execution, waits 30 seconds, then crashes... o_o


Here's the DIMs/Globals:





Here's the functions:





Here's the Type:





Thanks to all who help! :)

Last edited 2012


Guy Fawkes(Posted 2012) [#2]
Anyone?


Ross C(Posted 2012) [#3]
Please, for the love of all things good, stop bumping your threads when someone doesn't respond for a day. If someone wants to help you, they will. I can understand if your thread has dropped to the previous page. It's not even been a full 24 hours since you've posted.

Your posts for help are not any more or less important than anyone else's posts on this board for help. By bumping them when someone doesn't respond, you are elevating your post to the top, pushing other peoples further down the page.


Guy Fawkes(Posted 2012) [#4]
Ross. Stop destroying my threads. ESPECIALLY on my birthday... -.-


Ross C(Posted 2012) [#5]
It was your birthday yesterday, according to your posts. It's just decency on the forum not to bump your threads after such a short period.


Guy Fawkes(Posted 2012) [#6]
No, it is my birthday today. stop being rude. Im trying to be nice around u, but its getting REAL hard not to.


H&K(Posted 2012) [#7]
Its getting really hard to not be nice?

Ps on a programming/logic note you do realise you just said that it was easy to be nice to him?

pps. Bump after like a full page of other posts

Last edited 2012


RGR(Posted 2012) [#8]
.

Last edited 2012


Yasha(Posted 2012) [#9]
Chaps, lay off.

Not because I think Thundros deserves defence (gods no!), but because this is all really quite unnecessary. Ignore it and it'll go away. Free market helponomics!

If you want a mod, email one. They respond well, if you can formulate a proper complaint. I hate to say it but they're not going to hand down a ban over a bumped help request, and there's no reason to stir up something where they would.


Adam Novagen(Posted 2012) [#10]
Seconded. I gave up on these threads a long time ago; hell, only reason I opened this one is because I noticed Yasha had posted, and was curious to see what was up. Live, let live and move on eh? :)


ando(Posted 2012) [#11]
@ Thundros, sorry I don't have a solution for your code prob up there. But there is still a lot of nice people on this forum so maybe someone will help. :)

@ Yasha, also sorry. I've been ignoring a problem for a while in the hope it would pass but I think it's getting worse.

@ the nasties out there repeatedly ganging up with their personal attacks against one person, the hardest faults to see in people are usually our own.
I have a very strong belief that people should treat each other with respect and kindness.
The problem is there are too many people going around attacking those they see as inferior and then somehow seeing themselves as superior.
But isn't that a contradiction ? If you are lacking in patience, compassion and kindness etc, then how can you be a good person ? What's superior about that ?
It seems to me the worst people in the world are those that get pleasure from attacking others. To those people I say, Kneel to a cockroach because a cockroach is more superior than you.

To those not currently getting in to a kneelling position ( the good people), have a good day. :)

Edit- too many nasties on this forum with nothing being done about it....bye.

Last edited 2012


Guy Fawkes(Posted 2012) [#12]
Yea. Really. On my birthday. HOW nice. But I forgive u. as ando said, a cockroach is more superior than u. so good day to all u rude ppl :) i only want kind ppl in this thread. if i cant have that then lock it. lock it now :)


Midimaster(Posted 2012) [#13]
first: happy birthday to you Thundros from germany. I still believe in you and hope your life will become eaysier with getting older an wiser.

Now to your save function:


The main problem of reading/saving is always, that the data linedoesn't correspond to the variables, you expected in this moment.

1.
For finding errors an problems it it important to add a lot of DEBUGLOG lines in the code. Keep it there until your are 100% sure, that the code is working proper. When it works, do not delete those lines, but comment it out.

With this system you are able to talk to others, if you found problem im the code. You can communicate the last lines of this protocoll.


For c.obj = Each obj
     ; nmb=nmb+1
     ; DEBUGLOG "Check Object no=" + nmb



2.
You should divide different functionallities in different functions to find out, where the problem occurs and to keep it logical devided. (Excuse my bad english)

I would suggest to export the filling of the object to a separate function and also the copying of textures and creating of the BB3D files. All should be commentet by some DEBUGLOG lines:

Function ActualizeObjects()
	 For c.obj = Each obj  
		nmb=nmb+1
 		DEBUGLOG "Check Object no=" + nmb
		c\XPosition# = EntityX#(c\mesh,True)
		c\YPosition# = EntityY#(c\mesh,True)
		c\ZPosition# = EntityZ#(c\mesh,True)
		...
		SaveTexture c

....
End Function



Function SaveTextures(c:obj)
	   If c\fname$<>""
 		DEBUGLOG "Save Texture necessary"
		DEBUGLOG "Count Surfaces = " + CountSurfaces(c\mesh)
 		For S=1 To CountSurfaces(c\mesh)
			Surf = GetSurface(c\mesh,S)
			.....

End Function



Function SaveBB3D(c:obj) 
		   If c\fname$=""
			DEBUGLOG "Save BB3D necessary"
			c\fname$=F$+"d\"+c\mesh+".b3d"
			WriteBB3D(c\fname$,c\mesh)
		   EndIf
End Function



Function Save_File(fs$)
	savefile = WriteFile(f$)
	BombDir(f$+"d")
        CreateDir(f$+"d")
			
	 WriteLine(savefile, CountObjs())
	 For c.obj = Each obj
		nmb=nmb+1
 		DEBUGLOG "Save Info about Object no=" + nmb
		For S=1 To CountSurfaces(c\mesh)
			Surf = GetSurface(c\mesh,S)
			Brush = GetSurfaceBrush(Surf)
			Tex = GetBrushTexture(Brush)
			If Tex<>0 Then
				WriteLine(savefile, f$+"d\"+getfilename$(TextureName(Tex)))
          .....	        
End function




3.
For the save-file I always would prefer a text based file, where not only values are stored, but also a "keyword" is added:

 WriteLine(savefile, "CountObjects=" + CountObjs())
...
WriteLine(savefile, "X=" + c\XPosition#)
WriteLine(savefile, "Y=" + c\YPosition#)
WriteLine(savefile, "Z=" + c\ZPosition#)
....


You never can be sure, that each line correponds with the value, you might expect in this moment.

But if you use "keywords" you can check during loading, whether the line is the expected one.

Function Load_File()
.....
TextLine=ReadFile(Fl$)

If left(TextLine="Z=") Then
     c\ZPosition=mid(TextLine(3,-1)
Endif
.....





In sum it seems to be a lot of more work, but at the end it saves time, because the time necessary for finding of a reason for a error decreases. Change your coding style to a more secure one.



I think the problem in this code could be, that you do not save the numbers of surfaces. This may cause problems when reading it again (...and save it the next time...)


RemiD(Posted 2012) [#14]
Thundros>>I don't have time to debug your code, but i want to give you some tips in order to find where there is a problem in this code and in your future codes.

You want to separate your code into small parts, where each part corresponds to an event/action.

With this, rather than to use commentaries to explain how the program is supposed to behave, use either Debuglog() or Print() so that you can really track how the program behaves.

For example :
Instead of writting :
;Read and store the triangles in the mesh.

You want to write :
DebugLog("Read and store the triangles in the mesh.") ;or If(DebugMode% = 1) Print("Read and store the triangles in the mesh.") Endif


You can also use :
Flushkeys()
Waitkey()

After each of these debug lines or at the end of each function or at the end of each loop in order to be able to see how the program behaves.


Use the same thing for each part of your code and you will be able to see where is the error.


Also when there is a loop, use a variable to track the number of time the loop is executed so that you will know if the program doesn't behave as expected.

For example :
For TriangleI% = 1 To 10 Step 1
 Debuglog("TriangleI% :"+TriangleI%) ;or Print("TriangleI% :"+TriangleI%)
 Flushkeys()
 Waitkey()
Next

LoopsCount% = 0
Repeat
 LoopsCount% = LoopsCount% + 1
 Debuglog("LoopsCount% :"+LoopsCount%) ;or Print("LoopsCount% :"+LoopsCount%)
 Flushkeys()
 Waitkey()
Until(LoopsCount% = 10)

LoopsCount% = 0
While(LoopsCount% <= 10)
 LoopsCount% = LoopsCount% + 1
 Debuglog("LoopsCount% :"+LoopsCount%) ;or Print("LoopsCount% :"+LoopsCount%)
 Flushkeys()
 Waitkey()
Wend


Good luck.

Last edited 2012


Guy Fawkes(Posted 2012) [#15]
Thanks for the birthday wish, @Midimaster! :) I dont know why SOME of u ppl arent as nice. :) Thanks, @RemCoder :)


Midimaster(Posted 2012) [#16]
Well, what do you think about dividing the code into parts? What about adding more DEBUGLOGs? I would like to know your opinions...

Adding "keywords" to the save-file could help finding the error.

Last edited 2012