Solved

Caraf G

Posted on 2000-04-06
11
174 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
ID: 2689225
The error occurs on the line CopyMemory
0
 
LVL 1

Author Comment

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

Expert Comment

by:caraf_g
ID: 2689384
Does that mean you solved the problem?

If not, can you post the type definition for MyTSB?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:MitchBroadhead
ID: 2689411
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
ID: 2689414
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2689451
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
ID: 2689477
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
ID: 2689478
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
ID: 2689517
won't this slow the performance somewhat?
I'll give it a go though!!
0
 
LVL 1

Author Comment

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

Expert Comment

by:caraf_g
ID: 2689583
Glad I could help!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

831 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