Solved

Caraf G

Posted on 2000-04-06
11
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 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