Programmer error: Field/Type fatality

Archives Forums/BlitzMax Bug Reports/Programmer error: Field/Type fatality

BlitzSupport(Posted 2011) [#1]
I just screwed up and inadvertantly tried to call New with a field's name instead of its type, and it killed MaxIDE (though that usually doesn't happen). However, you do always get an "EXCEPTION_ACCESS_VIOLATION" even with the debugger on:


' Max...

Type Other
	Field myfield:Int
End Type

Type Test
	
	Field bg:Other
	
	Method Tester ()
		bg = New bg ' Should have typed Other!
	End Method
	
End Type

t:Test = New Test
t.Tester


For what it's worth, Monkey catches it!


' Monkey...

Class Other
	Field myfield:Int
End

Class Test
	
	Field bg:Other
	
	Method Tester ()
		bg = New bg ' Should have typed Other!
	End Method
	
End

Function Main ()
	Local t:Test = New Test
	t.Tester
End


Last edited 2011


kfprimm(Posted 2011) [#2]


Take a look at that! Looks like it's creating a duplicate of that type. And because bg is null, it is erroring out.

Also, if you call 'New Null' the compile errors with 'Subexpression for 'New' must be a user defined type or object.

Seems like this (syntactically) proper behavior. But it looks like the debug runtime isn't throwing a proper exception.


kfprimm(Posted 2011) [#3]
To fix the problem:

In brl.mod/brl.blitz/blitz_object.c, replace
BBObject *bbObjectNew( BBClass *clas ){
	int flags=( clas->dtor!=bbObjectDtor ) ? BBGC_FINALIZE : 0;
	BBObject *o=(BBObject*)bbGCAllocObject( clas->instance_size,clas,flags );
	clas->ctor( o );
	return o;
}


with,
BBObject *bbObjectNew( BBClass *clas ){
	if (clas == 0)
		return &bbNullObject;
	int flags=( clas->dtor!=bbObjectDtor ) ? BBGC_FINALIZE : 0;
	BBObject *o=(BBObject*)bbGCAllocObject( clas->instance_size,clas,flags );
	clas->ctor( o );
	return o;
}



Czar Flavius(Posted 2011) [#4]
I think you can use New on an existing object, which will create an object of that type. It depends whether it should create the exact type of the variable, or find it out dynamically (so it could create an extended type of a base type field).