fix fluid sim null ptr bug
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-01 15:49:48 -05:00
parent 569311a23e
commit 59be0068f1
8 changed files with 30 additions and 8 deletions

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Sun Dec 01 12:58:18 EST 2024
buildNumber=462
#Sun Dec 01 15:41:36 EST 2024
buildNumber=471

View File

@ -1207,6 +1207,7 @@ Add more debugging tools for fluids
Remove conditional update check in fluid sim
Explicit memory management of fluid chunk cache buffers
Fix GriddedDataCellManager memory leak caused by physics and ConcurrentHashMap
Fix fluid sim null pointer bug with unallocated chunks

View File

@ -2,5 +2,6 @@
#define SOLVER_CONSTS_H
#define LINEARSOLVERTIMES 5
#define VECTOR_DIFFUSE_TIMES 1
#endif

View File

@ -118,7 +118,7 @@ void simulate(
// printLayer(chunks[0]->u0[CENTER_LOC],targetLayer);
//solve vector diffusion
{
for(int l = 0; l < LINEARSOLVERTIMES; l++){
for(int l = 0; l < VECTOR_DIFFUSE_TIMES; l++){
//solve vector diffusion
for(int i = 0; i < numChunks; i++){
Chunk * currentChunk = chunks[i];

View File

@ -148,13 +148,22 @@ void readInChunks(JNIEnv * env, jobject chunkList, Environment * environment){
int chunkMask;
//solve chunk mask
int cSideArrPos = 0;
for(int i = 0; i < numChunks; i++){
chunkJRaw = getChunk(i);
chunkMask = calculateChunkMask(env,getBuffArr(dJId));
(*env)->SetIntField(env,chunkJRaw,chunkmaskJId,chunkMask);
//skip this chunk if the center array is not allocated (must not have been removed yet?)
if(
(*env)->GetObjectArrayElement(env,(*env)->GetObjectField(env,chunkJRaw,dJId),CENTER_LOC) == NULL ||
(*env)->GetDirectBufferAddress(env,(*env)->GetObjectArrayElement(env,(*env)->GetObjectField(env,chunkJRaw,dJId),CENTER_LOC)) == NULL
){
continue;
}
Chunk * newChunk;
if(i >= stbds_arrlen(chunkViewC)){
if(cSideArrPos >= stbds_arrlen(chunkViewC)){
// printf("allocate chunk %d\n",i);
// fflush(stdout);
newChunk = (Chunk *)malloc(sizeof(Chunk));
@ -164,10 +173,11 @@ void readInChunks(JNIEnv * env, jobject chunkList, Environment * environment){
// printf("new chunk %p\n",chunks[i]);
// fflush(stdout);
} else {
newChunk = chunkViewC[i];
newChunk = chunkViewC[cSideArrPos];
// printf("get chunk %d: %p\n",i,newChunk);
// fflush(stdout);
}
cSideArrPos++;
jd = (*env)->GetObjectField(env,chunkJRaw,dJId);
jd0 = (*env)->GetObjectField(env,chunkJRaw,d0JId);
u = (*env)->GetObjectField(env,chunkJRaw,uJId);

View File

@ -58,7 +58,7 @@ public class FluidCellManager {
int drawStepdownInterval = 3;
int drawStepdownValue = 25;
double drawRadius = 50;
double drawRadius = 5 * ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET;
int physicsRadius = 3;

View File

@ -460,6 +460,14 @@ public class ServerFluidChunk {
}
}
/**
* Checks if this chunk is allocated or not
* @return true if it is allocated, false otherwise
*/
public boolean isAllocated(){
return this.bWeights[CENTER_BUFF] != null;
}
/**
* Allocates the central arrays for this chunk
*/

View File

@ -72,7 +72,7 @@ public class ServerFluidManager {
ServerTerrainManager serverTerrainManager;
//controls whether fluid simulation should actually happen or not
boolean simulate = false;
boolean simulate = true;
@Exclude
/**
@ -291,7 +291,9 @@ public class ServerFluidManager {
public void queue(int worldX, int worldY, int worldZ){
if(simulate){
ServerFluidChunk fluidChunk = this.getChunk(worldX, worldY, worldZ);
this.simulationQueue.add(fluidChunk);
if(fluidChunk.isAllocated()){
this.simulationQueue.add(fluidChunk);
}
}
}