Solved

Caraf G

Posted on 2000-04-06
11
167 Views
Last Modified: 2010-05-02
For an extra 50 -

Further to our discussion on using CopyMemory to pass lists about:
I am getting an error with reading the memory.  Is there a maximum size of memory that I can copy?

I am now passing more points (as I need ordered triangles for OpenGL)

Dim mysglcoord() As sglCoordinate3D
Dim mycoords As Single
Dim i As Long

ReDim mysglcoord(1 To MyTSB.numTriangleCoords)

mycoords = MyTSB.sglTriangleCoords
CopyMemory VarPtr(mysglcoord(1)), mycoords, 12 * (MyTSB.numTriangleCoords)

Call glBegin(GL_TRIANGLES)
For i = 1 To MyTSB.numTriangleCoords
  Call glColor3f(1#, 1#, 0#)
  Call glVertex3f(mysglcoord(i).x, mysglcoord(i).y, mysglcoord(i).z)
Next i
Call glEnd
Call glFlush

I get the message:
The instruction at "0x77f970ab" referenced memory at "0x0ab7200". The memory could not be "read".

You know, the standard crashing error.  The size of the operation is all I can think of.
0
Comment
Question by:MitchBroadhead
  • 6
  • 5
11 Comments
 
LVL 1

Author Comment

by:MitchBroadhead
Comment Utility
The error occurs on the line CopyMemory
0
 
LVL 1

Author Comment

by:MitchBroadhead
Comment Utility
OK I have realised that the Ptr is a long instead of a single.
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Does that mean you solved the problem?

If not, can you post the type definition for MyTSB?
0
 
LVL 1

Author Comment

by:MitchBroadhead
Comment Utility
No I haven't solved the problem.

MyTSB.sglTriangleCoords fills an array:

Type VertexCoord
 x as single
 y as single
 z as single
end type

redim vertCoord(1 to numTriangleCoords) as vertexcoord

Then passes VarPtr(vertcoord(1)) back as a long.

0
 
LVL 1

Author Comment

by:MitchBroadhead
Comment Utility
Public Function sglTriangleCoords() As Long
Dim pointCounter As Long
Dim i As Long
Dim j As Long
Dim sglCoords() As VertexCoordinate

pointCounter = 1

ReDim sglCoords(1 To numTriangleCoords)

For i = 1 To MyTSB.SurfacePolygonIndices.Npolygons
   For j = 1 To MyTSB.SurfacePolygonIndices.SurfacePolygon(i).Nsides
     sglCoords(pointCounter) = MyTSB.VertexCoords.VertexCoordinate(MyTSB.SurfacePolygonIndices.SurfacePolygon(i).IndicesShort(j) + 1)
     pointCounter = pointCounter + 1
   Next j
 Next i

sglTriangleCoords = VarPtr(sglCoords(1))
'sglTriangleCoords = sglCoords(1)
End Function
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Hmmmm. Should be OK. A Single is 4 bytes too.

Perhaps a completely different tack is needed here. You may have to do some class programming after all...
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Ok, look at this idea:

1) Create a DLL with the following class (Class1)

Option Explicit
Private Type VertexCoordinate
    a As Single
    b As Single
    c As Single
End Type
Private arrTheThreeSinglesArray() As VertexCoordinate
Public Sub FillIt(lngLBound As Long, lngUBound As Long)

Dim lngCounter As Long
ReDim arrTheThreeSinglesArray(lngLBound To lngUBound)
For lngCounter = lngLBound To lngUBound
    arrTheThreeSinglesArray(lngCounter).a = lngCounter * 1
    arrTheThreeSinglesArray(lngCounter).b = lngCounter * 2
    arrTheThreeSinglesArray(lngCounter).c = lngCounter * 3
Next

End Sub
Public Property Get tLBound() As Long

tLBound = LBound(arrTheThreeSinglesArray)

End Property
Public Property Get tUBound() As Long

tUBound = UBound(arrTheThreeSinglesArray)

End Property
Public Property Get tA(Index As Long) As Single

tA = arrTheThreeSinglesArray(Index).a

End Property
Public Property Get tB(Index As Long) As Single

tB = arrTheThreeSinglesArray(Index).b

End Property
Public Property Get tC(Index As Long) As Single

tC = arrTheThreeSinglesArray(Index).c

End Property

0
 
LVL 10

Accepted Solution

by:
caraf_g earned 50 total points
Comment Utility
Then, the calling program could use it as follows:

Option Explicit
Private Type VertexCoordinate
    a As Single
    b As Single
    c As Single
End Type
Private Sub Command1_Click()

Dim objX As Class1
Dim typY As VertexCoordinate
Set objX = New Class1
objX.FillIt 1, 3

Dim lngCounter As Long

For lngCounter = 1 To 3
    typY.a = objX.tA(lngCounter)
    typY.b = objX.tB(lngCounter)
    typY.c = objX.tC(lngCounter)
    'Now you can use typY here
Next

End Sub
0
 
LVL 1

Author Comment

by:MitchBroadhead
Comment Utility
won't this slow the performance somewhat?
I'll give it a go though!!
0
 
LVL 1

Author Comment

by:MitchBroadhead
Comment Utility
The display flickers a bit when rotating the shape, but its good!!
Thanx again Caraf :)
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Glad I could help!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now