Hi,
Having problems with calls within my AppIdle routine (Eaccess violation raised!).
I have a modal form TfmRotateModel (yes, I'm using Delphi guys!) that holds tv3d to preview my models stuff. When open it, it runs OK, and can see my models n'that, problem is when I close it.
Modal routine looks like this:
procedure TfmMainForm.sbModelRotateClick(Sender: TObject);
var
fmRotateModel : TfmRotateModel;
begin
fmRotateModel := TfmRotateModel.Create(self);
try
begin
fmRotateModel.GetMRUList;
fmRotateModel.ShowModal();
end;
finally
begin
fmRotateModel.Free();
sbModelRotate.Down := false;
end;
end;
end;
The forms own create routine looks like this:
procedure TfmRotateModel.EngineCreate;
begin
TV := CoTVEngine.Create;
TV.Init3DWindowed(handle,true);
TV.SetDebugMode(true, true, true, true);
TV.SetDebugFile(ExtractFilePath(Application.ExeName) + '6_5_debugfile.txt');
// Lets display the FPS:
TV.DisplayFPS(true, 0);
Scene := CoTVScene.Create;
Global := CoTVGlobals.Create;
Atmos := CoTVAtmosphere.Create;
Inp:= CoTVInputEngine.Create;
Inp.Initialize(True, True); // Lets init both keyboard and mouse:
Land := Scene.CreateLandscape('Landscape1');
TexFactory := CoTVTextureFactory.Create;
//Tank := TTVMesh.Create(self);
// Actor := CoTVActor.Create;
end;
My AppIdle routine looks like:
procedure TfmRotateModel.AppIdle(Sender: TObject; var Done: Boolean);
begin
if TV <> nil then
begin
// This tells Windows it isnt done, so it will continue to loop.
done := false;
if Scene <> nil then
GetPosRotData;
// The actual render loop:
TV.Clear(false);
Atmos.Atmosphere_Render;
Land.Render;
//////////////////////////////
if Actor <> nil then
Actor.Render(true);
TV.RenderToScreen;
Application.ProcessMessages;
end
else
done := true;
end;
So, I'm testing that the TV pointers aren't null before using the Tv objects, seems that EVEN after the TForm closed, code enters the on Appidle routine and gets past the
if TV <> nil then
begin
and the
if Scene <> nil then
GetPosRotData;
into the 'GetPosRotData;' routine, which has another test, la:
procedure TfmRotateModel.GetPosRotData;
begin
if Scene <> nil then
begin
Scene.GetCamera.SetPosition(CameraPos.x,CameraPos.y,CameraPos.z);
Scene.GetCamera.SetRotation(RotateAngle.x,RotateAngle.y,RotateAngle.z);
end;
end;
Appears that the 'scene' object is not nil either, as calls the Scene.GetCamera.SetPosition routine,
which raises the exception.
Now, when the modal form is destroyed I attempt to clear all the memory allocated, and set
the pointers to nil, so behvaiour is unexpected. The Forms destroy routine looks like:
procedure TfmRotateModel.FormDestroy(Sender: TObject);
begin
if Actor <> nil then
begin
Actor.Destroy;
Actor:= nil;
end;
if TV <> nil then
begin
Scene := nil;
Inp := nil;
Global := nil;
Atmos := nil;
Land := nil;
TexFactory := nil;
//
TV.ReleaseAll();
TV := nil;
end;
end;
This routine is defnt. entered when close Form, but seems the routines held within the
forms AppIdle are entered (even though form destroyed

). So the Tv objects that have been set to nil, appear to pass the 'if object <> nil' test (even though I've set them to nil). So its not until the object is actually being used 'Scene.GetCamera.SetPosition' that the exception is raised.
Am I doing something daft?
Any clues anyone?
Ta,
Z