对于3DS的类似于家酿的克隆,我试图创建一个数据结构,称为包含一个位置的块,以及一个int的三维数组,其中数组中的int表示一个块ID。
其定义如下:
typedef struct{
Vector3 position; //Vector3 is a struct that simply contains xyz as floats, similar to Unity
int blocks[16][128][16]; //Array of ints, each int represents a block ID
} Chunk;为了填充一个块,我有一个函数,它接受一个指向变量的指针。它的意思是用它应该包含的块ID填充‘块’数组。
但是,这种情况不会发生,程序将挂起执行。其职能如下:
void generate_chunk(Chunk *chunk)
{
int newBlocks[16][128][16]; //Create temp 3D array
int x,y,z; //For loop coordinate values
for(x=0; x<16; x++) { //Loop X
for(z=0; z<16; z++) { // Loop Z
for(y=0; y<128; y++) { // Loop Y
//<enum> BLOCK_GOLD_ORE = 6, as a test
newBlocks[x][y][z]=(int)BLOCK_GOLD_ORE; //Set the value in the position xyz of the array to 6
}
}
}
/* The runtime then freezes/crashes whenever the array "newBlocks" is referenced. */
printf("\x1b[14;2Hgenerate_chunk :: %i", newBlocks[0][0][0]); //Debug print //!Crashes
//! vvv Uncomment when I've solved the problem above
//! memcpy(chunk->blocks, newBlocks, sizeof(chunk->blocks)); //Copy the temp array to the struct
}被称为:
Chunk newChunk;
generate_chunk(&chunk);所发生的情况是,每当以后引用数组或其任何值时,程序将挂起。
奇怪的是,如果我把调用函数放在if语句后面,程序仍然会冻结在第一个帧上,尽管它当时没有被调用。
更奇怪的是,如果我赋值时没有像这样的for循环:
void generate_chunk(Chunk *chunk)
{
int newBlocks[16][128][16]; //Create temp 3D array
newBlocks[0][0][0]=(int)BLOCK_GOLD_ORE; //Set its first value to 6 (enum)
printf("\x1b[14;2Hgenerate_chunk :: %i", newBlocks[0][0][0]); //Debug print, doesnt crash anymore
}程序不再挂起。每当我试图使用for循环分配值时,它似乎就失败了。我可能遗漏了一些显而易见的东西,但这促使我认为这甚至可能是编译器的一个问题(可能不是)
编译者是DEVKITPRO下的GCC。
谢谢!
发布于 2021-08-12 12:05:19
好的,3DS似乎不允许3D阵列在1919年左右,当所有的面都是相等的时候,尽管如果你使尺寸不相等的话,这可能是灵活的。
https://stackoverflow.com/questions/68712567
复制相似问题