EDIT 1
Here is a condensed bit of code that illustrates the crash. To test it open Data/Scripts/level.as and replace this code at the beginning:
Code: Select all
void Init(){
}
Code: Select all
class obj{}
obj@[] obj_handle_array(2); // this line causes the crash on re-compile.
void Init(){
obj temp_obj = obj();
}
You can avoid the crash when you move marked line into the init() function. For example this compiles fine every time:
Code: Select all
class obj{}
void Init(){
obj@[] obj_handle_array(2); // no longer causes issues
obj temp_obj = obj();
}
Of-course this way obj_handle_array will only exist in the scope of init(). If you want to have access to the array outside of init(), as well as avoid the Crash, you can do this:
Code: Select all
class obj{}
obj@[] obj_handle_array; // declares object handle array.
void Init(){
obj@[] obj_handle_array(2); // initializes object handle array.
obj temp_obj = obj();
}
The code in the original post tries to illustrate the need for such an odd array declaration, and was mostly intended to illustrate that the code was working, just not re-compiling.
ORIGINAL POST:
Basically I'm using Arrays, and object handles:
Code: Select all
/* Defining Variables and Objects*/
//An array of object handles of length 2.
my_object@[] my_array(2); // This specifically seems to be what prevents the code from re-compiling.
my_object test_object_one;
my_object test_object_two;
/* Defining Object Classes */
class my_object{
int my_value;
// object constructor
my_object(int new_value){
this.my_value = new_value;
}
}
/* Defining Functions Classes */
// this function is passed a handle to an object so the object can be modified directly.
void mod_object(my_object@ object_handle){
object_handle.my_value*=2;
}
// this is called when a level is first started.
void Init(){
test_object_one = my_object(1);
test_object_two = my_object(10);
@my_array[0] = @test_object_one;
@my_array[1] = @test_object_two;
Print("object one value:"+my_array[0].my_value+"\n");//should print 1
Print("object two value:"+my_array[1].my_value+"\n");//should print 10
mod_object(@my_array[0]); // function modifies the object that the handles in the array reference
mod_object(@my_array[1]);
Print("object one value:"+my_array[0].my_value+"\n");//should print 2
Print("object two value:"+my_array[1].my_value+"\n");//should print 20
}
I then just use a function that takes an object handle as an argument and modifies the original object to test that the handles are working correctly and then write some stuff to the console/terminal that shows those changes:
You can try this by opening Data/Scripts/level.as and replacing the "void Init(){}" line with the code I listed above.
Then start the alpha, open a level and look at the console (for mac you'll need to start it from the terminal, windows should always have it). It should output the values correctly as I mentioned in my comments, showing that everything works, but when you open level.as, and save it again, the alpha should crash.
The console/terminal will say "Bus error" and stop, and give a crash dump: http://pastebin.com/L5yP6XGy
I think you can recreate this error by just creating a custom object handle array, like so:
Code: Select all
my_object@[] my_array(2);
I'd like to submit this as a bug report to david, but would like more people to test it first, or correct me if I did something wrong.