Welcome! Log In Create A New Profile


Strange program freeze [RESOLVED]

Posted by owen 
Strange program freeze [RESOLVED]
July 12, 2012 05:27PM
Nothing worst than when you are coding and everything complies fine but one day compile the dol file, run it on the wii and the wii just freezes instanly. I have no clue why it happened. No crash screen, nothing. Just black. Is there anyway to debug this kind of crash?

Nothing is apparently wrong with the code because it was working fine the other day and I was just going through my usual changes/adding features etc. It could be the latest update of devkitpro but I didn't notice anything that may affect it. Plus all my other programs compile and run as they should.

So I decided to do some trial and error (by placing a exit(0) ) until I found the problem line;
	for(i=0; i<enemy_list_max; i++) {	
		enemy_add( get_random_world_vector(), randint(2)+1 );

If I put the exit(0) before enemy_add() the program runs to completion but if I put it AFTER the code hangs on the first line. It hangs in a weird way, it doesn't do ANY work at all on the wii (printf() calls before that line don't show up on screen). It just hangs as soon as the homebrew channel loads it. Worst thing is even if I comment out that line it still stops on other lines but I cannot identify WHY its stopping.

The rest of the functions are;

int world_size=18000, hits=0;

int randint(int rmax) { //generate a random number
	return (rand() % rmax + 1);

guVector get_random_world_vector(){	
	guVector new_pos={ randint(world_size)-(world_size*0.5f), 0, randint(world_size)-(world_size*0.5f) };
	return new_pos;

Anybody have any clue what could be the problem or a way to debug it?

Edited 2 time(s). Last edit at 07/13/2012 02:26AM by owen.
Re: Strange program freeze
July 12, 2012 10:04PM
For the enemy_add() function the program flow never actually entered the enemy_add() function. I'm doubt I am running out of memory because I have written large programs.

The enemy_add() function is like this;

void enemy_add(guVector pos, int type ){
	int free_slot=enemy_list_max;
	int i;	
	for(i=0; i<enemy_list_max; i++) {
		if(!enemy_list.active) {
	if(free_slot==enemy_list_max) return; //stage full
	guVector new_rot={ 0, randint(360),0 };




		case EN_SAUCER: enemy_list[free_slot].size=500; enemy_list[free_slot].speed=20; enemy_list[free_slot].health=100; break;
		case EN_SCOUT:  enemy_list[free_slot].size=100; enemy_list[free_slot].speed=default_forward-5; enemy_list[free_slot].health=5; break;
		default:        enemy_list[free_slot].size=500; break;
	//enemy_animate( i );
Re: Strange program freeze
July 13, 2012 02:25AM
After messing around with the size of my arrays it seems like I am running out of heap space or some kinda memory. I may have to rethink how I build my octree.

here are the structures that are eating up my heap :(

#define LISTSTRUCT_MAX 120

typedef struct {
	int list[LISTSTRUCT_MAX];
	int list_current;
	int list_max;
} ListStruct;


#define COLL_BOUNDS 80


typedef struct {
	int x_list[COLL_BOUNDS];  //stores coord keys
	int y_list[COLL_BOUNDS];
	int z_list[COLL_BOUNDS];
	int item_list[COLL_BOUNDS][COLL_BOUNDS][COLL_BOUNDS]; //stores 3d keys
	int item_current; //3d key counter
	int coordinate_current; //coord key counter
} CollisionRegionStruct;


#define COLL_GROUP_MAX 200

#define COLL_KEY_REGION_MAX 1000

#define COLL_LIST_MAX 10

typedef struct {
	int item_current;
	ListStruct group_list[COLL_GROUP_MAX];
	int key_region[COLL_KEY_REGION_MAX];
	int key_counter;
} CollisionStruct;


CollisionRegionStruct collision_region; 

CollisionStruct collision_list[COLL_LIST_MAX]; 


Edited 1 time(s). Last edit at 07/13/2012 02:26AM by owen.
Re: Strange program freeze [RESOLVED]
July 13, 2012 04:26AM
Those are not even 3 MB.

I don't know if this is your case (or if you are using it already) but I recommend you to give WiiMC's mem2 manager a try. I used to "run out of memory" when trying to allocate big blocks (5 MB~ or something like that) because of what I think was some sort of memory fragmentation and mem2 manager helped me go through it.

Potentially useful discussion: [devkitpro.org]

The code you posted does not use dynamic memory allocation but I'm sure that's not the only memory you are using so I thought it was worth sharing this. I don't know if MEM2 is considered when statically allocating memory either (I'd guess it is but that is just because that would be more convenient for us, I can not think of any real argument).
Re: Strange program freeze [RESOLVED]
July 13, 2012 05:05AM
At first I tried array[10000][10000][10000] and the compiler told me that the size of the array was too large. I really didn't need that much anyway. :)

@Aruskano thanx much but I will not venture into "dynamic memory" magic. I will stick with the simple stuff. I will just have to rethink how I size the arrays until I find the optimum mix.
Re: Strange program freeze [RESOLVED]
July 14, 2012 05:05PM
If it really is SRAM starvation, I'll run into issues every time you declare new variables. Using mem2 the legacy way isn't very hard either:

#include <ogc/lwp.h>
#include <ogc/lwp_heap.h>
#include <ogc/lwp_threadq.h>

static void *memStart = NULL;
static void *memEnd = NULL;
static heap_cntrl memHeap;

void initMem()
	u32 level, size;


	memStart = SYS_GetArena2Lo();
	memEnd = SYS_GetArena2Hi();
	size = memEnd - memStart;


	memset(memStart, 0, size);

	size = __lwp_heap_init(&memHeap, memStart, size, PPC_CACHE_ALIGNMENT);


void * allocMem(size_t size)
	void *newmem;
	heap_iblock info;

	newmem = __lwp_heap_allocate(&memHeap, size);//memalign(32, size);

	__lwp_heap_getinfo(&memHeap, &info);
	printf("tot %d free %d\n", info.free_size + info.used_size, info.free_size);
	return newmem;
void releaseMem(void * ptr, size_t size)
	if (!__lwp_heap_free(&memHeap, ptr)) {
		printf("Error freeing data.");

Edited 3 time(s). Last edit at 07/14/2012 05:06PM by DRS_.
Re: Strange program freeze [RESOLVED]
July 15, 2012 03:53AM
@DRS_ cool thanx. I really don't need much memory.

I also found another array bound bug in my menu system.
Sorry, only registered users may post in this forum.

Click here to login