Reading array causes crash ,stupid error?

support for the powerpc toolchain
Post Reply
perli55
Posts: 3
Joined: Sun Aug 28, 2011 7:33 pm

Reading array causes crash ,stupid error?

Post by perli55 » Sun Aug 28, 2011 7:44 pm

When I read from the array called "world" , my wii crashes and
dolphin emulator gives the error "tring to compile at 0,LR=00000000", this is my code:

Code: Select all

#include <stdlib.h>
#include <grrlib.h>
#include <math.h>
#include <ML.h>

#define BLACK  0xFFFFFFFF
#define RED    0xFF0000FF
#define GREEN  0x00FF00FF
#define BLUE   0x0000FFFF
#define YELLOW 0xFFFF00FF

#define random(min,max) ((min)+rand()%((max)+1))
#include <verdana_ttf.h>

f32 x=0;
f32 y=0;
f32 z=3;
f32 a1=0;
f32 a2=0;

int main()
{
	GRRLIB_Init();
	ML_Init();
	
	GRRLIB_ttfFont* font = GRRLIB_LoadTTF(verdana_ttf,verdana_ttf_size);
	void camera(void);
	GRRLIB_SetBackgroundColour(0x0,0xBB,0xBB,0xFF);
	GRRLIB_SetAntiAliasing(true);
	GRRLIB_SetLightAmbient(0x000000FF);
	srand(time(NULL));
	
	char str[64];
	
	// definition of "world" is here <---------------------
	u8 world[64][64][64];
	u8 tx=0;
	u8 ty=0;
	u8 tz=0;
	for (tx=0;tx<64;tx++) {
		for (ty=0;ty<64;ty++) {
			world[tx][ty][0]=1;
		}
	}
	
	while (!ML_Pressed(cHome))
	{
		ML_Update(0);
		camera();
		
		GRRLIB_3dMode(0.1,1000,90,0,1);
		GRRLIB_Camera3dSettings(x,y,z,0,0,1,x+cos(a1),y+sin(a1),z+sin(a2));
		GRRLIB_SetLightDiff(0,(guVector){x,y,z},3,1,0xFFFFFFFF);
		
		for (tx=0;tx<64;tx++) {
			for (ty=0;ty<64;ty++) {
				for (tz=0;tz<1;tz++) {
					//if (world[tx][ty][0]) // <---- uncommenting this results in crash
						GRRLIB_ObjectView(tx,ty,tz,0,0,0,1,1,1);
						GRRLIB_DrawCube(1,true,0x00FF00FF);
				}
			}
		}
		
		GRRLIB_2dMode();
		sprintf(str,"%.2f %.2f %.2f %d",x,y,z,5); // <---------------- replacing 5 with world[0][0][0] results in crash
		GRRLIB_PrintfTTF(10,40,font,str,16,YELLOW);
		
		GRRLIB_Render();
	}
	
	return 0;
}


void camera(void)
{
	if (ML_IrX<128)
		a1+=0.13;
	if (ML_IrX>640-128)
		a1-=0.13;
	if (ML_IrY<128)
		a2+=0.13;
	if (ML_IrY>480-128)
		a2-=0.13;
	if (a2>M_PI_2) {a2=M_PI_2;}
	if (a2<-M_PI_2) {a2=-M_PI_2;}
	
	if (ML_Held(cA)) {
		x+=cos(a1);
		y+=sin(a1);
		z+=sin(a2);
	}
	
	if (ML_Held(cB)) {
		x-=cos(a1);
		y-=sin(a1);
		z-=sin(a2);
	}
}

WinterMute
Site Admin
Posts: 1845
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Reading array causes crash ,stupid error?

Post by WinterMute » Sun Aug 28, 2011 10:14 pm

Your world array is larger than the stack allocated to the main thread, either declare it globally (outside your main function) or allocate it dynamically using new or malloc. I have no idea what <grrlib.h> or <ML.h> are either but you should probably be aware that we provide no support for libraries not supplied by devkitPro.
Help keep devkitPro toolchains free, Donate today

Personal Blog

perli55
Posts: 3
Joined: Sun Aug 28, 2011 7:33 pm

Re: Reading array causes crash ,stupid error?

Post by perli55 » Mon Aug 29, 2011 1:50 pm

WinterMute wrote:Your world array is larger than the stack allocated to the main thread, either declare it globally (outside your main function) or allocate it dynamically using new or malloc. I have no idea what <grrlib.h> or <ML.h> are either but you should probably be aware that we provide no support for libraries not supplied by devkitPro.
Thank you!

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests