PB procedures + structures + freeing memory errors
Posted: Thu Jan 06, 2005 12:59 am
I'm having an issue with passing/returning structures and freeing the memory afterwards.
Here's the PB code:
It works fine at first, but the problem I get is after about five seconds of holding the arrow keys to move, i get a "Instruction tried to read memory at address 0x00000000" error.
Any ideas? I've never tried passing structures through pb before so maybe I missed something obvious?
Here's the PB code:
Code: Select all
Structure I3D_NODEDATA
xPos.f
yPos.f
zPos.f
EndStructure
ProcedureDLL.l i3D_Node_GetData(nodeID.l) ; Gets the nodes data in a structure
*tmpNodeData.I3D_NODEDATA = AllocateMemory(SizeOf(I3D_NODEDATA))
*tmpNodeData = CallCFunction(i3D_Library,"pb_Node_GetData",nodeID)
ProcedureReturn *tmpNodeData
EndProcedure
In a loop I have:
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
i3D_Close3D()
ElseIf KeyboardPushed(#PB_Key_Left)
*ShipData.I3D_NODEDATA = i3D_Node_GetData(1)
i3D_Node_SetPosition(1,*ShipData\xPos + 0.05,0,0)
FreeMemory(*ShipData)
ElseIf KeyboardPushed(#PB_Key_Right)
*ShipData.I3D_NODEDATA = i3D_Node_GetData(1)
i3D_Node_SetPosition(1,*ShipData\xPos - 0.05,0,0)
FreeMemory(*ShipData)
EndIf
Code: Select all
//Get node data
API I3D_NODEDATA * CALLCONV pb_Node_GetData(int nodeID)
{
I3D_NODEDATA *data = new I3D_NODEDATA;
ISceneNode *node = pb_scene->getSceneNodeFromId(nodeID);
data->xPos=node->getAbsolutePosition().X;
data->yPos=node->getAbsolutePosition().Y;
data->zPos=node->getAbsolutePosition().Z;
return data;
}
Any ideas? I've never tried passing structures through pb before so maybe I missed something obvious?