Problem with Save function

Blitz3D Forums/Blitz3D Beginners Area/Problem with Save function

Guy Fawkes(Posted 2012) [#1]
I created a Save & Load function to save & load a "level.dat" file. In this code, I also included the "savemeshdx9" function, which saves all meshes on the screen to "DX9 (X)" format... Now when I go to do a load with Ctrl + L, for SOME reason, it crashes....


IDK why....


I should have called this thread "Problem with Load function"... But at any rate....


What is wrong with my save function, Ross?


I am using ur new code that u fixed in the delete thread.



Here's the functions:






Also, here's my check_control_keys() function as well:






check_control_keys() is how i call it in the main loop. with Control+S...


It's having a problem at:







To save, hold Ctrl + S | To load, hold Ctrl + L



Thanks again, Ross! :)

Last edited 2012


Ross C(Posted 2012) [#2]
The reason I have this bit at the top:

	If KeyDown(29) Or KeyDown(157) ; IF either LEFT or RIGHT CTRL held down
		If KeyHit(46) Then ; IF C key pressed
			copy_selected()
		End If
	
		If KeyHit(30) Then ; IF A key pressed
			select_all()
		End If

                ;PUT ANY CTRL+ KEYS IN HERE. ONLY CHECK FOR THE KEY, NOT THE CTRL PRESS
	Else


Is so you can slot in any CTRL + keys. Notice how control A and Control C only check for the A and C keys? I have nested this inside the check for the control keys. Once the code determines the CTRL key is pressed, it executes another IF statment, only checking for the actual A key or the C key.

Also, why are you putting in single and multiple select modes? These are built into the code. You hold Shift to multiple select and CTRL to minus select. There is no modes for this to happen. As for your save thing, I have no idea. My suggestion though, is don't save meshes. Your not physically creating a mesh from vertices and tris, so you can just save the filename of the loaded meshes, or the fact they are primatives. Then save information like position in a text file or whatever.


Guy Fawkes(Posted 2012) [#3]
i tried... for some reason. it crashes at the line i told u about above when i try to load the saved objects...


RifRaf(Posted 2012) [#4]
Could you keep your topic count under control, I dont think its helpful to make a new topic for every tiny variation of your program, you clearly require a lot of help. Why not make one topic called, HELP WITH MY EDITOR or something like that. you have over half the newest posts all pertaining to the same program code.

Last edited 2012


Ross C(Posted 2012) [#5]
Have you done a debuglog on the temp\mesh?


Guy Fawkes(Posted 2012) [#6]
i just tried... and it wont record temp\mesh....






Ross C(Posted 2012) [#7]
If you want to debug it before the error happens, you'll have to place the debuglog command before the potential error occurs, so before the entityalpha statement.


Guy Fawkes(Posted 2012) [#8]
I did what u said, and it returns the random ID of an object... thats why i dont get this :/


Ross C(Posted 2012) [#9]
It is returning a pointer essentially, pointing to where abouts in memory the mesh is stored. So you know the mesh exists (unless it has been freed and the object has not been deleted. What error message is being generated. Could you post the entire code? You must be freeing a mesh somewhere.


Guy Fawkes(Posted 2012) [#10]
No worries... I fixed it.... Hehe. I'll show u the whole code in a sec here :)


Guy Fawkes(Posted 2012) [#11]
JUST when I thought I fixed it, one last problem arose. How can I make it so that the level loads itself once instead of every single time I hold Ctrl + L?



Here's the code:







Any help is GREATLY appreciated! :)



Thanks! :)


Rob the Great(Posted 2012) [#12]
Global levelloaded = 0

If KeyDown(CTRL)
   If KeyHit(L)
      If Not levelloaded
         Load_File(f$)
         levelloaded = 1
      EndIf
   EndIf
EndIf

;If you ever need to reload the level, reset levelloaded back to 0

Also, many Blitzers on this forum, myself included, are going to be very let down if you continue to neglect deleting Objects after deleting the meshes. In your function above, this line:
If trapt = 1 Then FreeEntity(c\mesh)

needs to become these lines:
If trapt = 1
   FreeEntity(c\mesh)
   Delete c
EndIf

or else it is going to give you a memory access violation when you try to select an object after loading the level.

It's an easy mistake, and I'm sure every OOP programmer has made that mistake at least once, so to save yourself a ton of debugging hours later, try to get in the habit of typing in "Delete c" immediately after typing in "FreeEntity(c\mesh)".

Hope this helps.


Ross C(Posted 2012) [#13]
It don't help, when you have 3 blank lines in between each line of code. It's murder to read. You should know the answer to that question really. Just call the load function, instead of loading it in response to a keyhit.

Last edited 2012


Guy Fawkes(Posted 2012) [#14]
Thanks, Rob! :) Thanks, Ross! :)