On the OSX version of PureBasic, I have problems releasing 3d lines (CreateLine3D) with the FreeMesh function after having included them in a node. Freeing 3d line mesh causes the program to crash. This only occurs, AFAIK, with 3d lines. I've mentioned this in the OSX Bugs forum, but haven't received any feedback yet.
Has any one else observed this under OSX or the Windows and Linux versions, or is there something "special" about 3d lines which requires "special" handling?
FreeMesh and 3d Lines
Re: FreeMesh and 3d Lines
try this code "Meridians and Parallels" by einander . it has keywords FreeMesh ,CreateLine3D, MoveNode, ... so it may be relevant to your problem, it works okay on windows system for PB 522LTS. just change this
line 139
from CameraLocate(0, 0, 0, 400) to MoveCamera(0, 0, 0, 400)
line 140
from AttachNodeObject(0,CameraID(0),#PB_Node_Camera) to AttachNodeObject(0,CameraID(0))
line 139
from CameraLocate(0, 0, 0, 400) to MoveCamera(0, 0, 0, 400)
line 140
from AttachNodeObject(0,CameraID(0),#PB_Node_Camera) to AttachNodeObject(0,CameraID(0))
Re: FreeMesh and 3d Lines
in the following example (in windows) we attach the 3d line mesh to node then if we want to free the mesh we should first detach it from node
If KeyboardReleased(#PB_Key_Space)
DetachNodeObject(#node, MeshID(0))
FreeMesh(0)
EndIf
also using KeyboardReleased instead KeyboardPushed
here before we exit we should add :
DetachNodeObject(#node, MeshID(0))
FreeMesh(0)
to the program closing procedure when we press we press ESC or click 'X'
may be this needs a more looking since pressing 'x' should free everything. but temporary we can free the resources first ourself
here press Space key before closing the program to detach the mesh from the node and then free the mesh
other approach is to use something like this to draw a 3d line
CreateMesh(0, #PB_Mesh_LineList, #PB_Mesh_Static)
MeshVertexPosition(-5, 0, -5)
MeshVertexColor(RGB(255,0,0))
MeshVertexPosition(-5, 0, 5)
MeshVertexColor(RGB(0,255,0))
FinishMesh(#True)
look example MeshManual2.pb
below we will draw 2 lines
here we can attach the mesh to entity and do what we want, i have'nt tested it with a node.
If KeyboardReleased(#PB_Key_Space)
DetachNodeObject(#node, MeshID(0))
FreeMesh(0)
EndIf
also using KeyboardReleased instead KeyboardPushed
here before we exit we should add :
DetachNodeObject(#node, MeshID(0))
FreeMesh(0)
to the program closing procedure when we press we press ESC or click 'X'
may be this needs a more looking since pressing 'x' should free everything. but temporary we can free the resources first ourself
here press Space key before closing the program to detach the mesh from the node and then free the mesh
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - CreateLine3D
;
; (c) 2011 - Fantaisie Software
;
; ------------------------------------------------------------
;
#CameraSpeed = 1
#node = 35
IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
; Line3D
;
CreateLine3D(0, 0, 0, 0, RGB(255, 0, 0), 10, 0, 0, RGB(255, 0, 0))
CreateNode(#node, 0, 0, 0)
AttachNodeObject(#node,MeshID(0))
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 5, 5, 5, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
Repeat
Screen3DEvents()
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Space)
DetachNodeObject(#node, MeshID(0))
FreeMesh(0)
EndIf
EndIf
RotateNode(#node,1,1,0,#PB_Relative)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
Screen3DStats()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
CreateMesh(0, #PB_Mesh_LineList, #PB_Mesh_Static)
MeshVertexPosition(-5, 0, -5)
MeshVertexColor(RGB(255,0,0))
MeshVertexPosition(-5, 0, 5)
MeshVertexColor(RGB(0,255,0))
FinishMesh(#True)
look example MeshManual2.pb
below we will draw 2 lines
here we can attach the mesh to entity and do what we want, i have'nt tested it with a node.
Code: Select all
#CameraSpeed = 1
IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
CreateMesh(0, #PB_Mesh_LineList , #PB_Mesh_Static)
MeshVertexPosition(-5, 0, -5)
MeshVertexColor(RGB(255,0,0))
MeshVertexPosition(-5, 0, 5)
MeshVertexColor(RGB(0,255,0))
MeshVertexPosition(-10, 0, -5)
MeshVertexColor(RGB(255,0,0))
MeshVertexPosition(-10, 0, 5)
FinishMesh(#True)
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
SetMeshMaterial(0, MaterialID(0))
CreateEntity(0,MeshID(0),MaterialID(0) )
; Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 20, 5, 20, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
Repeat
Screen3DEvents()
If ExamineKeyboard()
EndIf
RotateEntity(0, 0,1,0,#PB_Relative)
RenderWorld()
Screen3DStats()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Re: FreeMesh and 3d Lines
DetachNodeObject(#node, MeshID(0)) works! Thank you!
Nonetheless, this does not appear to be necessary with other meshes when running on OSX.
Nonetheless, this does not appear to be necessary with other meshes when running on OSX.