Skip to content

Commit

Permalink
Fixed bug in radiusGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
TCA166 committed Aug 10, 2023
1 parent 25218c0 commit dd8ec85
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endif
all: CFLAGS := -O3
all: radiusGenerator modelGenerator chunkExtractor regionFileReader

debug: CFLAGS := -Wall -Werror -Wpedantic
debug: CFLAGS := -Wall -Werror -Wpedantic -g
debug: radiusGenerator modelGenerator chunkExtractor regionFileReader

cNBT.o:
Expand Down
2 changes: 1 addition & 1 deletion chunkParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ unsigned int getSections(unsigned char* nbtFileData, long sz, section* sections)
propertyString = appendProperty(propertyString, north, "north");
}
if(open != NULL){
propertyString = appendProperty(propertyString, part, "open");
propertyString = appendProperty(propertyString, open, "open");
}
if(part != NULL){
propertyString = appendProperty(propertyString, part, "part");
Expand Down
2 changes: 2 additions & 0 deletions mtlGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def writeMaterialSection(o:TextIOWrapper, name:str, rgb:tuple, d:float) -> None:
rgb[2] = 113 / 255
if "top" in filename and t:
filename = filename.replace("_top", "", 1)
if "water_still" in filename:
writeMaterialSection(o, filename[:-4].replace("_still", ""), rgb, rgb[3])
writeMaterialSection(o, filename[:-4], rgb, rgb[3])
else:
writeMaterialSection(o, filename[:-4], (1, 1, 1), 1)
Expand Down
65 changes: 37 additions & 28 deletions radiusGenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,37 +296,46 @@ int main(int argc, char** argv){
printf("%.2f%% done\r", ((float)progress / (float)numChildren) * 100);
fflush(stdout);
//in theory we have to check the WIFEXITED
if(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS){
int childNum = 0;
for(int i = 0; i < counter; i++){
if(childrenPids[i] == wpid){
childNum = i;
break;
if(WIFEXITED(status)){
int exitStatus = WEXITSTATUS(status);
if(exitStatus == EXIT_SUCCESS){
int childNum = 0;
for(int i = 0; i < counter; i++){
if(childrenPids[i] == wpid){
childNum = i;
break;
}
}
size_t size = -1;
ssize_t res = read(fd[childNum][READ_END], &size, sizeof(size_t));
if(res < 0){
pipeError("parent", "reading 1");
}
if(size < 1){
pipeError("parent", "reading-size value invalid");
}
parts[childNum] = malloc(size);
close(fd[childNum][READ_END]);
int shmid = shmget(parentId + childNum, size, 0644);
if(shmid < 0){
shmError("parent shmget");
}
char* shmBuffer = (char*)shmat(shmid, NULL, 0);
if(shmBuffer == NULL){
shmError("parent shmat");
}
strcpy(parts[childNum], shmBuffer);
shmdt(shmBuffer);
//having done what we wanted to do now we can just remove this shared segment
shmctl(shmid, IPC_RMID, 0);
currentSize += size;
}
size_t size = -1;
ssize_t res = read(fd[childNum][READ_END], &size, sizeof(size_t));
if(res < 0){
pipeError("parent", "reading 1");
}
if(size < 1){
pipeError("parent", "reading-size value invalid");
}
parts[childNum] = malloc(size);
close(fd[childNum][READ_END]);
int shmid = shmget(parentId + childNum, size, 0644);
if(shmid < 0){
shmError("parent shmget");
}
char* shmBuffer = (char*)shmat(shmid, NULL, 0);
if(shmBuffer == NULL){
shmError("parent shmat");
else{
fprintf(stderr, "Process %d failed with exit status:%d", wpid, exitStatus);
}
strcpy(parts[childNum], shmBuffer);
shmdt(shmBuffer);
//having done what we wanted to do now we can just remove this shared segment
shmctl(shmid, IPC_RMID, 0);
currentSize += size;
}
else if(WIFSIGNALED(status)){
fprintf(stderr, "Process %d failed by signal %s.\n", wpid, strsignal(WTERMSIG(status)));
}
else{
fprintf(stderr, "Process %d failed.\n", wpid);
Expand Down

0 comments on commit dd8ec85

Please sign in to comment.