Solved

Caraf G

Posted on 2000-04-06
11
177 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

687 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