unhandled exceptin : Unhandled Memory Exception

BlitzMax Forums/BlitzMax Programming/unhandled exceptin : Unhandled Memory Exception

hy :)
i was programming and found it

unhandled exceptin : Unhandled Memory Exception Error

can anyone tell what is this? Because i'm lost! don't know if it's a internal blitzmax error or mine.

Thanks :)

Have you got debug switched on for a better error or any example code?

ok,
i've two lines inside a method
blitzmax shows this error on the first line,
if i comment the first line, it shows the same error in the second,
if i comment the second, and add a third line, it shows the same error at the third line!!!

i just don't know what's is it..
the code is big, a lot of bmx files, etc...

lolz.. i dun know ... really dun

thx

Paste the offending lines here, else no one can help.

I think there are a large number of posible causes for this, not all of them have to due with memory. For instance I had a divide by zero bug that caused the same error message. It was neccessary to put in print statements to find where the program was acutally bombing out.

For fun if you are using FlushMem comment it out, if you aren't using it put it in the main program loop. Just to see if it makes a difference.

well
i've verified and i'm not makin division by 0..
i've already have commented and uncommented the flushmem lines..
and the error continues
i've tried the print statements and it just showed me that the error is inside a single method that calls another two! because if i comment it, the error not happens anymore. But i'll have a NullPointer... =/

the lines are inside that method

Method initGame ()

Print "a"

Self.adminDepartament = AdminDepartament.createAdminDepartament( Size.createSize( 10, 10 ) )

Print "b"

Self.clock = Clock.createClock( NORMAL )

Print "c"

EndMethod

and it justs prints "a"
but if inside the method createAdminDepartament i put some print at the first line of it, it's NOT printed!!!

it's like blitzmax abort the execution when the method is called...
i just can't understand...

thx :)

I get these all the time.
Very common when working with external functions which tries to write to "forbidden" parts of the memory due to passing faulty pointers or external functions using the wrong calling convention.

External functions using the wrong calling convention can be tricky to spot sometimes since they can actually be called a couple of times until the stack is messed up.

I'd say that you might be getting a null pointer reference in the Size.createSize() call. put some print statements in there to see if it gets all the way through.

thx for the tip
but i'm have verified and i'm not getting a null pointer in Size.createSize().

should i contact mark? lolz

thx

Also you should have all included files open in the ide, otherwise the debugger won t mark the error line if the error is in a file which is closed. It took time for me to realize that, lol.

Double clicking on the entries in the debug window will open the file with the offending line. From personal experience I would check to see if you forgot a Return statement in your CreateSize function / method.

ok guys
I've tried oppened ALL the files and error continues without logical cause...
I've verified all the methods that returns something and ALL the returns are there!!! no one missing!!!

i can't understand... =/

thx

put in a temporary variable like so and at the debugstop you can check to see what your variables are doing

local size:TSize=Size.createSize( 10, 10 )
debugstop
Self.adminDepartament=AdminDepartament.createAdminDepartament( size )

also, use Strict at the top of your program to avoid spelling mistakes and don't call your type and your instances the same name - (blitzmax is not case sensitive so adminDepartament and AdminDepartament are exactly the same token and so could mean a variety of things in the code above)

Perhaps you meant to write

Self.adminDepartament=TAdminDepartament.createAdminDepartament( size )

which would use the Type and not the uninitialized instance to locate the createAdminDepartament Function (it surely is not a method???)

ok
i used the DebugStop now and before it too...
and all the values of variables are all correct!!!
the Strict appears at the top of all files!!!
yes it is a Function.. i've already verified it too... for all types envolved.
i tried the TAdminDepartament and BlitzMax do not even compiled it. It said that the identifier TAdminDepartament wasn't found.

i'm lost...

thx

Call your Type TAdminDepartment and your field AdminDepartment that way BlitzMax knows exactly what you are referring to.

At the moment I think the compiler suspects you are actually wanting:

self.AdminDepartment=Self.AdminDepartment.CreateAdminDepartment()

which is causing a null pointer because the right hand side is using the null Self.AdminDepartment field not the TAdminDepartment type to locate the CreateAdmin function.

thx
i've tried it too, using
self.AdminDepartment=Self.AdminDepartment.CreateAdminDepartment()

but the error continue...

=/

Did you change the name of the type and the field like Skids suggested?

yes i have
and the error continues...

sorry I was a bit ambiguous, what you do want to do is this:

self.AdminDepartment=TAdminDepartment.CreateAdminDepartment()

me?
i have an atribute (field) in my class (type) called adminDepartment : AdminDepartment

when im calling AdminDepartment.CreateAdminDepartment() the function CreateAdminDepartment() returns me a new AdminDepartament instance.


:)

So, i put all my files in a host (http://www.insanegames.v10.com.br/all.zip) please, cold anyone help me, this is to my final project and i don't wanna convert to java (and learn java 2d...)

Please! Tks by now!
PS: The code is written in Brazilian Portuguese...

Check the change of the typename in the code below...

Jogo.bmx
'Jogo
'	@author Daniel Castro Scapin
'
'Abriga, controla e atualiza elementos lógicos chaves
'
'Depende:
'	DepartamentoAdministrativo	(administração da lógica do jogo)
'	Relogio						(tempo relativo do jogo ao real)
'	Atualizador					(atualização gráfica e lógica)


Strict

Import "DepartamentoAdministrativo.bmx"
Import "Relogio.bmx"
Import "Atualizador.bmx"

Type Jogo
	
	Field departamentoAdministrativo : TDepartamentoAdministrativo
	Field relogio : Relogio
	
	'Private
	'horas inicial e final do dia
	Const RELOGIO_INICIAL : String	= "07:00:00"
	Const RELOGIO_FINAL : String	= "12:00:00"
	
	'Private
	'velocidades do jogo
	Const RAPIDO : Float	=	0.0001
	Const NORMAL : Float	=	0.001
	Const LENTO : Float		=	0.01
	
	'Construtor
	Function criarJogo : Jogo ()
		Local myjogo : Jogo = New Jogo
		myjogo.inicializarJogo()
		Return myjogo
	EndFunction
	
	Method inicializarJogo ()
		'cria um deptoAdm que tem um mapa de tamanho dado
		Local tam:Tamanho = Tamanho.criarTamanho( 10, 10 )
		Self.departamentoAdministrativo = TDepartamentoAdministrativo.criarDepartamentoAdministrativo(Tam)
		Self.relogio = Relogio.criarRelogio( NORMAL )
	EndMethod
	
	'Private
	Method atualizar ()
		Atualizador.atualizar( departamentoAdministrativo, relogio )
		
		relogio.atualizar()
		
		'quando a hora final é atingida o estado das estruturas é
		'atualizado
		If( relogio.estaIgual( RELOGIO_FINAL ) ) Then
			departamentoAdministrativo.atualizarEstruturas()
			relogio.setRelogioIgual( RELOGIO_INICIAL )
		EndIf
		
	EndMethod
	
	'Public
	
	Method aumentarVelocidade()
		relogio.setSegundoImaginario( Max( RAPIDO, relogio.getSegundoImaginario()/10 ) )
	EndMethod
	Method diminuirVelocidade()
		relogio.setSegundoImaginario( Min( LENTO, relogio.getSegundoImaginario()*10 ) )
	EndMethod
	Method normalizarVelocidade()
		relogio.setSegundoImaginario( NORMAL )
	EndMethod
	
	Method executar ()
		
		FlushKeys
		
		While Not KeyHit( KEY_ESCAPE )
			Cls
			
			atualizar()
			
			Flip
			FlushMem
		Wend
		FlushMem
		
	EndMethod
	
EndType




DepartamentoAdministrativo.bmx
'DepartamentoAdministrativo
'
'O Objetivo desse tipo é nos fornecer o numero total de alunos matriculados na escola, e a 
'capacidade de poder matricular e desmatricular algum aluno
'
'dependencia
'	NotaGradual
'	Secretaria
'	SalaDeAula	
'	Horario	
'	Relatorio
'	Aluno
'	Professor
'	NPC
'	Mapa
'	Relogio
'

Strict

Import "Secretaria.bmx"
Import "Horario.bmx"
Import "Relatorio.bmx"
Import "NotaGradual.bmx"
Import "Aluno.bmx"
Import "Mapa.bmx"
Import "Construtor.bmx"
Import "Relogio.bmx"

Type TDepartamentoAdministrativo

	'Atributos
		
	'compõe o departamento, necessária para a existencia desse
	Field secretaria : Secretaria
	
	'grade das Listas de escalacao dos professores para as salas
	Field horario : Horario
	
	'relatorio com informações sobre a escola
	Field relatorio : Relatorio
	
	'nota atribuida a escola pelo MinisterioDaEducacao
	Field notaGradual : NotaGradual
	
	'privado, serve para proporcionar a construcao de Estruturas
	Field mapa : Mapa
	
	'Construtor
	Function criarDepartamentoAdministrativo : TDepartamentoAdministrativo( areaMapa : Tamanho )
		Local departamento : TDepartamentoAdministrativo = New TDepartamentoAdministrativo
		departamento.inicializarDepartamentoAdministrativo( areaMapa )
		Return departamento
	EndFunction
	
	Method inicializarDepartamentoAdministrativo( areaMapa : Tamanho )
		Self.secretaria = Secretaria.criarSecretaria()
		Self.horario = Horario.criarHorario()
		Self.notaGradual = NotaGradual.criarNotaGradual() 'inicia com nota média
		Self.mapa = Mapa.criarMapa( areaMapa.getLargura(), areaMapa.getAltura() )
		Self.gerarRelatorio()
	EndMethod
	
	'Setters e Getters
	
	Method getSecretaria : Secretaria ()
		Return secretaria
	EndMethod
	
	Method getHorario : Horario ()
		Return horario
	EndMethod
	Method setHorario ( horario : Horario )
		Self.horario = horario
	EndMethod	
	
	Method getRelatorio : Relatorio ()
		Return Relatorio
	EndMethod
	
	Method gerarRelatorio ()
		Self.relatorio = Relatorio.criarRelatorio( secretaria.getNumeroDeAlunos(), secretaria.getNumeroDeProfessores() )
	EndMethod
	
	Method getNotaGradual : NotaGradual ()
		Return notaGradual
	EndMethod
	Method setNotaGradual ( nota : NotaGradual )
		Self.notaGradual = nota
	EndMethod
	
	Method getMapa : Mapa ()
		Return mapa
	EndMethod

	'adiciona uma estrutura ao Mapa
	Method adicionarEstrutura ( estrutura : Estrutura )
		Construtor.construir( estrutura, mapa )
	EndMethod
	
	
	Method atualizarEstruturas ()
		For Local linha : Int = 0 To mapa.getTamanho().getLargura()-1
			For Local coluna : Int = 0 To mapa.getTamanho().getAltura()-1
				Local terreno : Terreno = mapa.getTerreno( linha, coluna )
				If( ( Not terreno.estaVazio() ) And ( Not terreno.ocupadoPorTerreno() ) ) Then
					terreno.getOcupador().getEstado().proximoEstado()		
				EndIf
			Next
		Next
	EndMethod	
		
EndType		
	


You will have to change the secreteria.bmx file as well since you will get the same error on that...
Basically the problem is that you shouldn't have a type field with the same name as an existing type...
like this line...
Field secretaria : Secretaria

yeah!!!
:D
thx

that was the problem:
"Basically the problem is that you shouldn't have a type field with the same name as an existing type..."

thank you all for helping us out :D

:)))

ps: the code was removed from the server...
when we finish the game it'll be opensource :)) and we'll public it here!!!
ths a lot again :D

Actually, it's what skidracer suggested all along but I guess you misunderstood him. :)

Crazy !!
I have the same problem !!
Thank to this post I found the bug