I'm trying to delete all the scene objects in the GLScene container and I use the following code snippet to do it, but for some unknown reasons it crashes raises the segmentation fault when I try to free the object.
I tried to debug line by line and it revealed that somehow container class of Glscene1.Objects[i]
contains some inexplicable classes which has the '#2' class name. I 've tried to run through the very same code snippet w/o calling the Free method then there doesn't occur any abnormalitie, objects are not deleted but there is consistency in object class names.
for i := 0 to GLScene1.Objects.Count - 1 do
begin
if (not GLScene1.Objects[i].ClassNameIs('TGLCamera')) and
(not GLScene1.Objects[i].ClassNameIs('TGLLightSource')) and
(not GLScene1.Objects[i].ClassNameIs('TGLDummyCube')) and
(not GLScene1.Objects[i].ClassNameIs('TGLXYZGrid')) and
(not GLScene1.Objects[i].ClassNameIs('TGLSceneRootObject')) then
begin
// if GLScene1.Objects[i].Count > 0 then
// GLScene1.Objects[i].DeleteChildren;
GLScene1.Objects.Remove(GLScene1.Objects[i],false);
if GLScene1.Objects[i] <> nil then // I comment out these lines
GLScene1.Objects[i].free; // I comment out these lines
end;
end;