Yo! I've run into a rather strange problem trying to instantiate a struct with array members, where a stack overflow occurs. I'm using rustc 1.2.0-nightly (0cc99f9cc 2015-05-17) (built 2015-05-17). Here's what the struct looks like:
pub struct Apu {
ram: [u8; RAM_LEN],
ipl_rom: [u8; IPL_ROM_LEN],
smp: Option<Smp>,
timers: [Timer; 3],
left_output_buffer: [i16; BUFFER_LEN],
right_output_buffer: [i16; BUFFER_LEN],
//overflow_buffer: RingBuffer,
is_ipl_rom_enabled: bool,
dsp_reg_address: u8
}
impl Apu {
pub fn new() -> Apu {
Apu {
ram: [0; RAM_LEN],
ipl_rom: [0; IPL_ROM_LEN],
smp: None,
timers: [Timer::new(256), Timer::new(256), Timer::new(32)],
left_output_buffer: [0; BUFFER_LEN],
right_output_buffer: [0; BUFFER_LEN],
//overflow_buffer: RingBuffer::new(),
is_ipl_rom_enabled: true,
dsp_reg_address: 0
}
}
// Lots more impl stuff, unrelated
and I instantiate it like so:
let mut apu = Apu::new();
when running this, it panics with the following output:
thread '<main>' has overflowed its stack
None of the fixed-size arrays are larger than 64000 elements or so, but when I comment them out, the code works. What's MORE strange is I tried to isolate the code with this example:
const THE_SIZE: usize = 65536;
struct Lol {
member1: [u8; THE_SIZE],
member2: [u8; THE_SIZE],
member3: [u8; THE_SIZE],
member4: [u8; THE_SIZE],
some_other_member: bool
}
impl Lol {
fn new() -> Lol {
Lol {
member1: [0; THE_SIZE],
member2: [0; THE_SIZE],
member3: [0; THE_SIZE],
member4: [0; THE_SIZE],
some_other_member: true
}
}
}
fn main() {
let mut lol = Lol::new();
println!("this works perfectly");
}
but I can't seem to get it to break in the same way.
The full code for my breaking project can be found here (latest master):
https://github.com/yupferris/samurai_pizza_cats
and the exact command to run it that causes the bug is as follows:
cargo run -- test/ferris-nu.spc test/smashit.spc
again, I've tried to isolate the problem in much simpler test cases, but to no avail. It seems the problem only occurs when I have a certain amount array members in the struct, and doesn't seem to occur if I do things like comment out the rest of the function in which the struct is initialized. Very very strange happenings here.
Any help is appreciated!