memory acces vio..

Blitz3D Forums/Blitz3D Beginners Area/memory acces vio..

Santiworld(Posted 2009) [#1]
hi, i have some problem when compile my program..

when i run the program under blitz, the program work ok

if i compile and run the .exe, the msg, "memory acces violation"

i noted some b3d files fail when i load, so, i fix the b3d...
but, in the middle of the programs, allways fail, only in .exe

what can i do to check?, i use some print "any accion of my program...
becouse debuglog not work when i compile a bb file to a exe.

what can i do to found the error?

thanks... :)


Warner(Posted 2009) [#2]
So in your IDE, it runs correctly, but as an EXE it doesn't.
Have you tried compiling in debug mode? Or running in release (non-debug) mode from the IDE?
There are commands that are not protected when the program runs in release mode, for instance CreateSphere():
The segments value must be in the range 2-100 inclusive, although this is only checked in debug mode.

Tracing the error might be helpful, maybe you could leave out certain parts when compiling. First big parts, then smaller parts till you found the point where the error occurs.
I think there must be something that is different in your program when it is run from the IDE, and when it is run as an EXE. It could be the filepaths or some DLL's that cannot be found.


_PJ_(Posted 2009) [#3]
Sorry if this is unghelpful or you already know etc., but you haven't moved the exe after compilation have you? Or used dll/decls files from your B3D userlibs folder that are not in a userlibs folder your application?


Santiworld(Posted 2009) [#4]
hi, i run the .exe in the same directory i have all .bb files...

the include and dll are all in the same directory (root) game directory.

i add debug lines in the file.. like: print "load car mesh"

but, i have problems like, in the first time i load a b3d, is ok, the second time i load the same b3d, return memory acces vio..

i don't know... i go to try to remove all textures and materials in my b3d..

maibe have problems with textures?, if i load a texture using vram? can i have problems?, maibe is that. i don't know..

i using ode, fastext, shadows, and fasttext, but i don't have erros from this libs commands...

my game structure is this..

start
- graphics3d
- declarations

menu
clearworld(1,1,1)
- load menu
- loop menu
- destroy menu data

race
clearworld(1,1,1)
- load race data
- race loop
- destroy race data

all functions...


i have to many erros, i think my problem is in b3d files material and texure images...


Warner(Posted 2009) [#5]
If that is the case, the program should run with much simpler models.
There are circumstances when Renderworld gives a MAV. I believe it does that when there are too many vertices on a surface.
Also, not freeing certain objects could cause errors.
However, and that's important. There shouldn't be a difference between running from the IDE and running the EXE's other than file paths and userlibs.

If you don't know at what point the program crashes, than that is something to figure out first. Knowing that could provide vital clues to determine the cause of the crash.
I would go for the trial and error fault finding method. Comment out everything so the program runs. Run it to see if it works. Then uncomment everything one block at the time to see at what point is starts to fail.


Santiworld(Posted 2009) [#6]
thanks..

i am doing that now.... :)


_PJ_(Posted 2009) [#7]
Some blitz Exe's just don't work on some machines too, (TCK's Trashman gives a MAV for me :( )

I make use of my own Debug function which outputs to a log every function.
Very handy for finding the precise cause and/or point of the error.

Function Debug(sDebugFunction$="APPLICATION_RUN",sDebugResult$="LOG START",ExitFlag=False)
	If (Not(DebugOn))
		Return
	End If
	
	Local fDebug
	
	If (Not(FileType(fLogfile$)))
		fDebug=WriteFile(fLogfile$)
		WriteLine(fDebug,LSet$(CurrentDate(),12)+Chr$(9)+" | "+Chr$(9)+LSet$(CurrentTime(),9)+Chr$(9)+" | "+Chr$(9)+LSet$("APPLICATION_RUN",25)+Chr$(9)+" | "+Chr$(9)+"LOG START")
		CloseFile fDebug
	End If
		fDebug=OpenFile(fLogfile$)
		
	SeekFile(fDebug,FileSize(fLogfile$))
	Local sLine$=LSet$(CurrentDate(),12)+Chr$(9)+" | "+Chr$(9)+LSet$(CurrentTime(),9)+Chr$(9)+" | "+Chr$(9)+LSet$(sDebugFunction$,25)+Chr$(9)+" | "+Chr$(9)+sDebugResult
	WriteLine(fDebug,sLine$)
	CloseFile fDebug
	If (ExitFlag)
		ExitApplication(sDebugFunction$)
	End If
End Function



Santiworld(Posted 2009) [#8]
i working all day in this errors...

some b3d i made, have problems with the materrials.. so, i test with the b3d withot more than one standar blitz material, and the problem was fix..

my problem, was in a few b3d material...
the strange thing is, some b3d, only fail in the second time i load that mesh.. using loadmesh("mesh.b3d") command



Malice, i can't understand what do the function you post...
i tryit but no have restults.. thanks...


Warner(Posted 2009) [#9]
Then create a separate testing program that loads the models a number of times. If that causes problems, you could perhaps as a workaround load the model only once, and then use CopyEntity() instead.
I think maybe something (texture/brush/buffer?) is not freed when the model is freed. Maybe, instead of .B3D, you could come up with your own format instead. That way you have more control over what is loaded and what is freed.


Santiworld(Posted 2009) [#10]
thanks, thats a good idea, make something to test all before use in a program..

i use loadmesh(blabla.b3d) and next, use copyentity(blabla) to create, all wheels for example...


xlsior(Posted 2009) [#11]
Are you using the latest release of B3D?

some of the older versrions could trigger DEP exceptions if you tryr to launch them...


_PJ_(Posted 2009) [#12]
Sorry Latatoy, the function is ripped direct from my program so has some parameters and such that are pre-defined and another funciton for closing the app with a verbose message if necessary.

Here's a runnable example (with a sample function imitating a simple LoadMesh() )
Global fLogfile$=(CurrentDir$()+"Debug Log.txt")	;Path & Filename of Debug log
Global DebugOn=True									;True= Debug acctive   / False=Inactive


Function Debug(sDebugFunction$="APPLICATION_RUN",sDebugResult$="LOG START",ExitFlag=False)
	;sDebugFunction$:	Name of the current function
	;sDebugResult$: 	Any details for the Debug log
	;ExitFlag:			If TRUE then application will terminate with an error message. If FALSE, Application will try to continue.
	
	If (Not(DebugOn))
		Return
	End If
	
	Local fDebug
	
	; Ensures there is a Debug Fiel to write to, if not, it will make a new one.
	If (Not(FileType(fLogfile$)))
		fDebug=WriteFile(fLogfile$)
		WriteLine(fDebug,LSet$(CurrentDate(),12)+Chr$(9)+" | "+Chr$(9)+LSet$(CurrentTime(),9)+Chr$(9)+" | "+Chr$(9)+LSet$("APPLICATION_RUN",25)+Chr$(9)+" | "+Chr$(9)+"LOG START")
		CloseFile fDebug
	End If
	fDebug=OpenFile(fLogfile$)
	
	SeekFile(fDebug,FileSize(fLogfile$))
	Local sLine$=LSet$(CurrentDate(),12)+Chr$(9)+" | "+Chr$(9)+LSet$(CurrentTime(),9)+Chr$(9)+" | "+Chr$(9)+LSet$(sDebugFunction$,25)+Chr$(9)+" | "+Chr$(9)+sDebugResult
	WriteLine(fDebug,sLine$)
	CloseFile fDebug
	If (ExitFlag)
		ExitApplication(sDebugFunction$)
	End If
End Function




Function ExitApplication(sExitMessage$)
	; If An unfixiable error occurs, this can be used to give a more meaningful error message onscreen.
	AppTitle "Application Error","Critical Error in Function: "+sExitMessage$
	ClearWorld
	EndGraphics
	End
End Function













;Just add calls to the Debug() function in your program functions to monitor and check for errors.
Function MyFunction(sParameter$)
	Debug("MyFunction","Loading: "+sParameter$)
	Local LoadSomething=LoadMesh(sParameter$)
	If Not(LoadSomething)
		Debug("MyFunction","Error: "+sParameter$+ "Not found",True)
	End If
	Debug("MyFunction","Loaded: "+sParameter$+" to "+LoadSomething)
	Return LoadSomething
End Function



GIB3D(Posted 2009) [#13]
Function ExitApplication(sExitMessage$)
	; If An unfixiable error occurs, this can be used to give a more meaningful error message onscreen.
	AppTitle "Application Error","Critical Error in Function: "+sExitMessage$
	ClearWorld
	EndGraphics
	End
End Function


From what I've read, you don't need ClearWorld and EndGraphics if you're just going to use End because that frees everything in the program anyways. ClearWorld only needs to be used to free certain entities. EndGraphics is only needed if you want to screw up your program before calling the Graphics command.


PowerPC603(Posted 2009) [#14]
You can also add some extra lines to make sure your meshes/textures/sounds/... are loaded correctly:

mesh = MyLoadMesh("Test.b3d")

Function MyLoadMesh(FileName$)
	mesh = LoadMesh(FileName$)
	If mesh = 0 Then
		RuntimeError "Failed to load mesh: " + Chr$(34) + FileName$ + Chr$(34)
	Else
		Return mesh
	EndIf
End Function



_PJ_(Posted 2009) [#15]
From what I've read, you don't need ClearWorld and EndGraphics if you're just going to use End because that frees everything in the program anyways. ClearWorld only needs to be used to free certain entities. EndGraphics is only needed if you want to screw up your program before calling the Graphics command.

Yeah, I just put these in for completeness. I've heard rumours of memory not being freed and stuff, so just wanted to be sure.

and, PowerPC603,

You can also add some extra lines to make sure your meshes/textures/sounds/... are loaded correctly:

This is unnecessarily bloated, as within the MyLoadMesh function, all that is required is:

Mesh=LoadMesh(Filename$)
Debug("MY LOAD MESH","LOAD "+Filename$+" AS "+Mesh,(1-(sgn(Mesh))))


This will automatically 'Exit Application' if 'Mesh' fails to load.


Anywwwwayyy...
Latatoy, any luck?


Santiworld(Posted 2009) [#16]
wow, this is like university school for me...

i am very slow to aplly and understand that kind of code...

i using the last version of b3d...

thanks.. i am very bad programer in this topic of files, error etc..

malice, i aplly your function in a little program, if i try to load a filename incorrect, the b3d close inmediaty without msgs...
if the file is ok, the program run perfectly..

now, i found the log.txt!!, that is a good one!..

06 Jun 2009 | 11:10:51 | APPLICATION_RUN | LOG START
06 Jun 2009 | 11:10:51 | MY LOAD MESH | LOAD cript\bola.b3d AS 25900688
06 Jun 2009 | 11:11:10 | MY LOAD MESH | LOAD cript\bola.b3d AS 25900688
06 Jun 2009 | 11:11:15 | MY LOAD MESH | LOAD cript\bol1a.b3d AS 0
06 Jun 2009 | 11:11:17 | MY LOAD MESH | LOAD cript\bol1a.b3d AS 0
06 Jun 2009 | 11:12:24 | MY LOAD MESH | LOAD cript\bola.b3d AS 25900688
06 Jun 2009 | 11:15:48 | MY LOAD MESH | LOAD cript\bola.b3d AS 25900688
06 Jun 2009 | 11:15:53 | MY LOAD MESH | LOAD cript\b6ola.b3d AS 0
06 Jun 2009 | 11:15:57 | MY LOAD MESH | LOAD cript\b6ola.b3d AS 0
06 Jun 2009 | 11:16:09 | MY LOAD MESH | LOAD cript\b4ola.b3d AS 0
06 Jun 2009 | 11:16:22 | MY LOAD MESH | LOAD cript\bola.b3d AS 10406584
06 Jun 2009 | 11:19:06 | MY LOAD MESH | LOAD ico.jpg AS 0

the jpg file is only to check :p what happend :)


thanks malice..
this is a good tool to check the program :)

if the sdebugresult is 0, i can try to load another emergency mesh... to avoid the program crash...


:)


Santiworld(Posted 2009) [#17]
now i make a test, compile all game and media in a .exe file..

your function malice is perfect to test when the .exe file...

thanks again.....


_PJ_(Posted 2009) [#18]
if the sdebugresult is 0, i can try to load another emergency mesh... to avoid the program crash...


Yep, I wonder if there's somtehing wrong (i.e. corrupted) with the .b3d files themselves?

Anyway, for the exe version, you don't necessarily need to keep the 'Debug' on.

Instead of
Global DebugOn = True


Use something like

Global DebugOn = Sgn(Instr(CommandLine$(),"/debug"))


That way, you can choose to run it with the debugger by using a command line of "/debug"


Santiworld(Posted 2009) [#19]
this info is very usefull, thanks Malice! :)


Santiworld(Posted 2009) [#20]
same problem back...

i made some changes in b3d files....

my aplication crash, using the debug function of malice, i noted the program crash when try to load B3D files.. using LOADMESH command.


for some reason, sometimes,the file is load, sometimes no...

i go to report this in bugs, maybe is a b3d thing, or maibe is some in blitz function code...


someone has a "memory acces violation" sometimes and somethimes the same file is loaded correctly without problems?

regards, sorry but i can fix this...

This only happend when i compile my blitz program... using blitz compiler, or ideal, or blitzview.. the same...


_PJ_(Posted 2009) [#21]
Did you install the latest B3d update?
I wonder (not meaniing to confuse the issue if someone with more knowledge can shed any light on whether this is a possiblity or not)
but maybe something got changed in with that?

Otherwise, I cnan only assume it's something to do with the mesh files themselves. What programs did you use to create/convert them?


Santiworld(Posted 2009) [#22]
i am using blitz v1.100

to create the b3d i use the last vestion of b3d pipeline, with max9

i thing, this problem is a mix betten blitz an my b3d files..

i note, some failes only fails if i change other files, is realy strange...

maybe the texture are loaded in the memory and crash with other texture who loadmesh try to load..

i am using clearworld(), but i use freeentity freetexture, and freeimage before use the clearworld, and the problem persist..

example:


CLEARWORLD(1,1,1)
;MENU
LOADMESH ("car.b3d")
;this car.b3d have some textures, automatic loaded if the
;textures are in the same directory of b3d file
;where the loadmesh() function puts that two texture maps i have?

while not keyhit ()
updateworld()
renderworld()
flip()
wend

;RACE

CLEARWORLD 1,1,1
LOADMESH ("car.b3d")
;this car.b3d have some textures, automatic loaded if the
;textures are in the same directory of b3d file
;where the loadmesh() function puts that two texture maps i have?

while not keyhit ()
updateworld()
renderworld()
flip()
wend

when the race if finish, go back to menu, clearworld, load menu files, and start the menu loop.


_PJ_(Posted 2009) [#23]
Oh I posted in the Content Creation tools thread when I saw it there.

Are you wanting to use textures that are with the mesh in 3ds Max, or ignore those and apply your own from elsewhere?


Santiworld(Posted 2009) [#24]
i only mention about the textures, becouse maybe that is the problem...

i don't have tools to check where the loadmesh fails with my file...
or if exist a conflict in textures when i load diferent meshes with same textures...

i don't know, but thanks malice, you give me a big tool, now i now where exaclty the .exe fails with your function debug...

the question now is time to find the problem and fix it


i report this in blitz bugs..


Santiworld(Posted 2009) [#25]
i post the debug.txt runin the game with blitz witout blitz debug..

the program run perfectly :


_______________________________________________________________________________________________________
18 Jun 2009 | 10:28:56 | INICIO DE PROGRAMA | line 15
18 Jun 2009 | 10:28:56 | Loading default setup. | line 63
18 Jun 2009 | 10:28:56 | MENU | line 384
18 Jun 2009 | 10:28:56 | Clearworld (1,1,1) | line 0
18 Jun 2009 | 10:28:56 | menu_load() | LOAD menu\world_info.bmp AS 34889128
18 Jun 2009 | 10:28:57 | menu_load() | LOAD skyes\night.b3d AS 34912048
18 Jun 2009 | 10:28:57 | trying to open menu 3d | line 1948
18 Jun 2009 | 10:28:57 | menu_load() | LOAD menu\principal.b3d AS 34947080
18 Jun 2009 | 10:28:57 | menu_load() | LOAD menu\control1.b3d AS 62626576
18 Jun 2009 | 10:28:57 | menu_load() | LOAD menu\control2.b3d AS 62520344
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\hitire.b3d AS 62518800
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\r7low.b3d AS 62563744
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\carmesh.b3d AS 98850816
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\luces.b3d AS 62605328
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\lucesT.b3d AS 62581720
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\frente.b3d AS 99220496
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\interior.b3d AS 62533720
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\opticas.b3d AS 62466464
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD cars\engine.b3d AS 99359024
18 Jun 2009 | 10:28:58 | MENU LOAD | LOAD pilot\conductor.b3d AS 62707744
18 Jun 2009 | 10:29:01 | RACE | line 672
18 Jun 2009 | 10:29:01 | Clearworld (1,1,1) | line 0
18 Jun 2009 | 10:29:03 | RACE LOAD | Pista 1 tracks\arthun\ode.b3d AS 61130768
18 Jun 2009 | 10:29:03 | RACE LOAD | Pista 2 tracks\arthun\detail.b3d AS 62462896
18 Jun 2009 | 10:29:03 | RACE LOAD | Pista 3 tracks\arthun\arboles.b3d AS 35232440
18 Jun 2009 | 10:29:03 | RACE LOAD | Pista 4 tracks\arthun\helpers.b3d AS 62625000
18 Jun 2009 | 10:29:03 | Track_ode trimesh | line 787
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD cars\hitire.b3d AS 60699464
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD cars\r7low.b3d AS 99510144
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD cars\carmesh.b3d AS 35062352
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD cars\luces.b3d AS 34920808
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD cars\lucesT.b3d AS 34920128
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD cars\frente.b3d AS 35140304
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD cars\interior.b3d AS 99419808
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD cars\opticas.b3d AS 62531016
18 Jun 2009 | 10:29:04 | MENU LOAD | LOAD cars\engine.b3d AS 62413520
18 Jun 2009 | 10:29:04 | RACE LOAD | LOAD pilot\conductor.b3d AS 99717808
18 Jun 2009 | 10:29:04 | RACE LOAD | Loading sound sounds\motor4.wav AS 62621496
18 Jun 2009 | 10:29:04 | RACE LOAD | Loading sound sounds\skid.wav AS 61614520
18 Jun 2009 | 10:29:26 | MENU | line 384
18 Jun 2009 | 10:29:26 | Clearworld (1,1,1) | line 0
18 Jun 2009 | 10:29:26 | menu_load() | LOAD menu\world_info.bmp AS 100389496
18 Jun 2009 | 10:29:27 | menu_load() | LOAD skyes\night.b3d AS 60901800
18 Jun 2009 | 10:29:27 | trying to open menu 3d | line 1948 >>> in .exe file program crash here
18 Jun 2009 | 10:29:27 | menu_load() | LOAD menu\principal.b3d AS 61484328 >>> this b3d file have some problems, and crash the program only if is a .exe program compiler
18 Jun 2009 | 10:29:27 | menu_load() | LOAD menu\control1.b3d AS 60814072
18 Jun 2009 | 10:29:27 | menu_load() | LOAD menu\control2.b3d AS 60770488
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\hitire.b3d AS 61892648
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\r7low.b3d AS 61470744
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\carmesh.b3d AS 62382104
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\luces.b3d AS 61263200
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\lucesT.b3d AS 60668072
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\frente.b3d AS 101074968
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\interior.b3d AS 60643304
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\opticas.b3d AS 61072064
18 Jun 2009 | 10:29:27 | MENU LOAD | LOAD cars\engine.b3d AS 61257760
18 Jun 2009 | 10:29:28 | MENU LOAD | LOAD pilot\conductor.b3d AS 101076080
18 Jun 2009 | 10:29:30 | FIN DE PROGRAMA | line 578




Santiworld(Posted 2009) [#26]
now i try using DDS textures, but the problem is the same... :(


Santiworld(Posted 2009) [#27]
i found the origin of the problem...

when i use CLEARWORLD(1,1,1) the .exe crash

but i y use CLEARWORLD(0,1,1) the .exe never crash....

is a clearworld entities problem?, or part of my code?
i go to try to unload all entities using freeentity...


Santiworld(Posted 2009) [#28]
now the program still crashing using or not the clearworld...

i delete clearworld lines in my game, but still crashing with "memory aceess violation"

i replace clearworld, and write "freeentity " for all entitys, is the same, program crash, i delete all freeentitys and clearowlrds, , and is the same...

i replace all Loadmesh for Createsphere(4) and the program still crashing.

i write the game with all advices i recive in the forum, but i can relase the demo becouse the program dosent work when i compiler...

posible problems, blitz compiler, loadmesh function and loadanimmesh.. .b3d file, b3d pipeline exported? in b3dviewer i load alltimes perfectly

thanks malice for all replys, but, i try everything, and the problem, still.

how can i check if the problem is b3d file?, exist a method to check the integriti of a file?, or a debug mode for loadmesh function() step by step?


please.. need some help.


Warner(Posted 2009) [#29]
So the program crases even if you replace LoadMesh with CreateSphere?
That is not too good. Your problem reminds me of this situation:
Graphics3D 800, 600, 0, 2

parent = CreatePivot()
cube = CreateCube(parent)

FreeEntity parent
FreeEntity cube ;<----entity is allready freed

This could also occur internally, when using bones.
Have you compiled the .exe with debug enabled? The above situation will return "entity is allready freed" instead of "memory access violation".

Maybe it is due to the plugins you are using, you were using them, right?
Perhaps in non-debug mode situations certain memory range checking is not done.
Try compiling a version of the program without any plugins.


Santiworld(Posted 2009) [#30]
hi warner..

i follow your advice, i compile and test with blitz, debug o normal mode, is the same, allways the same Error! , mav

i found in the forum this funciton, i good to freeentity all childs

Function ClearEntity(mesh)
For i = 1 To CountChildren(mesh)
ClearEntity GetChild(mesh, i)
Next
FreeEntity mesh
End Function

now, i go to try to delete all libraries...
i have this include libraries

Include "JV-ODE.bb"
Include "speedtext.bb"
Include "FastImage.bb"
Include "FastExt.bb"
Include "ShadowsSimple.bb"

thanks, i try to take off all of this... to see what happend

thanks for the answer :)


Warner(Posted 2009) [#31]
Not sure if that is needed, since FreeEntity "will also free all children entities parented to the entity".


Santiworld(Posted 2009) [#32]
ah, i go to try that..

thanks warner..

i desactivated all libraries expect jv ode, and the .exe it looks like it works...

i go to make more test..

thanks!


_PJ_(Posted 2009) [#33]


parent = CreatePivot()
cube = CreateCube(parent)

FreeEntity parent
FreeEntity cube ;<----entity is allready freed


FreeEntity "will also free all children entities parented to the entity".


Oh I never knew that. Kinda handy to know, but also could cause probs if you're not watching for it.

I'm glad it seems to be working, Latatoy :)