Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1111249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:31:02+00:00 2026-05-17T02:31:02+00:00

this is really strange, i have an array in delphi and fill it with

  • 0

this is really strange, i have an array in delphi and fill it with directX matrices. then i get the pointer to the first element and pass it via com to c# managed code:

function TMPlugTransformInPin.GetMatrixPointer(out SliceCount: Integer; out
    ValueP: Int64): HResult;
var
  matrices: array of TD3DMatrix;
  i: Integer;
begin
  SliceCount := UserSliceCount;

  //make a temp array of all matrices
  SetLength(matrices, SliceCount);
  for i := 0 to SliceCount - 1 do
    matrices[i] := FTransformManager.ModelMatrix[i];

  //return a pointer to the first matrices cell [0,0]
  if SliceCount = 0 then
    ValueP := 0
  else
    ValueP := Int64(@matrices[0]);

  Result := S_OK;
end;

on managed side the code looks like this:

if (IsChanged)
            {
                int sliceCount;
                long source;

                FTransformIn.GetMatrixPointer(out sliceCount, out source);
                SliceCount = sliceCount;

                System.Diagnostics.Debug.WriteLine(source);

                if (FSliceCount > 0)
                    Marshal.Copy(new IntPtr(source), FData, 0, FData.Length);
            }

this all works for an array size up to 4136 (66176 floats), but for higher counts, the pointer to the array gets invalid..

any ideas?

thanks a lot!
thalm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:31:02+00:00Added an answer on May 17, 2026 at 2:31 am

    Your matrices variable is a local dynamic array. At the end of the function, the array’s reference count is reduced to zero and the array is destroyed. The pointer you stored in ValueP is invalid no matter how big the array was. The fact that it appears to work for smaller values just means you’re unlucky. (If you were lucky, the code would have crashed every time, which is a bigger clue that your code is wrong than when it only crashes sometimes.)

    You need to find some other way to manage the lifetime of that array. It will need to belong to something bigger than just that function. Maybe you can return the array itself from that function, or maybe you can make the matrices variable be a field of the class instead of a local variable. Or you could just return @FTransformManager.ModelMatrix[0].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.