So I stripped down Omeganaut from all its sounds, and commented out all calls to them, and the game is running just fine.
But if I add one sound component again, then it crashes after a few frames with the SYSTEM_$$_WAITFREE_VAR$PMEMCHUNK_VAR+36
So, the issue might be related to audio or possibly another problem that's not present in the simple audio test but appears in Omeganaut—such as BitmapExpression, MeshExpression, or other factors. I'm going to focus on tracking down BitmapExpression bugs with threads activated, tracing everything to see if I can find something, just like I did with the audio
Edit:
That was fast
Calling exit directly on TBitmapExpression.PixelTask displays black pixels, but still crashes after a while.
BUT
Calling exit directly onTBitmapExpression.ProduceOutput displays white pixels and doesn't crash!!!
Edit 2:
More precisely, the problem seems to be coming around
TaskCount := ZMath.Min(H, Tasks.WorkerCount);
So I added traces:
Code: Select all
procedure TBitmapExpression.ProduceOutput(Content : TContent; Stack: TZArrayList);
var
SourceB,B : TZBitmap;
H,W,I : integer;
Pixels,P : PColorf;
TaskCount,RowsLeft : integer;
TaskList : pointer;
Task : PPixelTask;
TaskH : integer;
begin
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Entering function'));
SourceB := GetOptionalArgument(Stack);
if SourceB<>nil then
begin
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: SourceB assigned from optional argument'));
B := TZBitmap.CreateFromBitmap( SourceB );
Pixels := SourceB.GetCopyAsFloats;
SourceB.Free;
end
else
begin
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: SourceB assigned from Content'));
B := TZBitmap.CreateFromBitmap( TZBitmap(Content) );
Pixels := nil;
end;
W := B.PixelWidth;
H := B.PixelHeight;
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Bitmap dimensions: W=' + IntToStr(W) + ', H=' + IntToStr(H)));
if Pixels=nil then
begin
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Pixels is nil, allocating memory'));
GetMem(Pixels,W * H * 16 );
FillChar(Pixels^,W * H * 16, 0);
end;
B.SetMemory(Pixels,GL_RGBA,GL_FLOAT);
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Tasks.WorkerCount= ' + IntToStr(Tasks.WorkerCount)));
TaskCount := ZMath.Min(H, Tasks.WorkerCount);
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: TaskCount= ' + IntToStr(TaskCount)));
GetMem(TaskList,TaskCount*SizeOf(TPixelTask));
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: TaskList memory allocated'));
Task := TaskList;
RowsLeft := H;
TaskH := H div TaskCount;
P := Pixels;
for I := 0 to TaskCount-1 do
begin
Task.P := P;
Task.W := W;
Task.H := TaskH;
Dec(RowsLeft,TaskH);
if I=TaskCount-1 then
Inc(Task.H,RowsLeft); //if any rows are left then add to last task
Task.Y := I*TaskH;
Task.YStep := 1/(H-1);
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Task ' + IntToStr(I) + ' - Y=' + IntToStr(Task.Y) + ', H=' + IntToStr(Task.H)));
Inc(Task);
Inc(P,W*TaskH);
end;
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Running tasks'));
Tasks.Run(Self.PixelTask,TaskList,TaskCount,SizeOf(TPixelTask));
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Freeing memory...'));
FreeMem(TaskList);
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: TaskList memory freed'));
// Needed to send the bitmap to OpenGL
B.UseTextureBegin;
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Texture use started'));
FreeMem(Pixels);
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Pixels memory freed'));
Stack.Push(B);
AndroidLog(PAnsiChar('TBitmapExpression.ProduceOutput: Bitmap pushed to stack, exiting function'));
end;
Oh, and with threads deactivated (just ZClasses.Tasks.Enabled := False; is sufficient now), it runs fine.
Here's the full log: