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 6981455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:09:35+00:00 2026-05-27T18:09:35+00:00

Im allocating memory to a double pointer in another function, therefore I need to

  • 0

Im allocating memory to a double pointer in another function, therefore I need to use a pointer to the pointer to the pointer. Im getting an exception thrown when i use sscanf, im not sure exactly why. Heres a snippet of the code. This was working earlier when it was all in the same function and i only needed to use double pointers, but now that im refactoring the code and using triple pointers im having this issue.

typedef float vector[3]

int mainLoaderFunc() {

    char* memory = NULL;
    size_t size = loadFile(fileName, &memory); // load model file into memory, this works, tested and true

    // create vector arrays
    vector *vertexArray = NULL;         
    vector *normalArray = NULL;         
    vector *textureArray = NULL;        

    loadArrays(size, memory, &vertexArray, &normalArray, &textureArray);

    // do other stuff with arrays

}

void loadArrays(size_t size, char *memory, vector **vertexArray, vector **normalArray, vector **textureArray) {

    int numVerts = 0; 
    int numNormals = 0;  
    int numTextures = 0;  

    char* p = memory;           // pointer to start of memory
    char* e = memory + size;    // pointer to end of memory

    // count verts, normals, textures for memory allocation
    while (p != e) {
        if (memcmp(p, "vn", 2) == 0) {
            numNormals++;
        } else if (memcmp(p, "vt", 2) == 0) { 
            numTextures++;
        } else if (memcmp(p, "v",  1) == 0) {
            numVerts++;
        } 
        while (*p++ != (char) 0x0A);
    }

    // allocate memory for vector arrays
    *vertexArray        = new vector[numVerts];
    *normalArray        = new vector[numNormals];
    *textureArray       = new vector[numTextures];

    p = memory;

    int vertexIndex = 0;
    int normalIndex = 0;
    int textureIndex = 0;  //*** IF BREAK POINT HERE: NO EXCEPTION

    // load data from memory into arrays
    while (p != e) {

        if (memcmp(p, "vn", 2) == 0) {
            sscanf(p, "vn %f %f %f", &normalArray[normalIndex][0], &normalArray[normalIndex][1], &normalArray[normalIndex][2]);
            normalIndex++;
        } else if (memcmp(p, "vt", 2) == 0) {
            sscanf(p, "vt %f %f", &textureArray[textureIndex][0], &textureArray[textureIndex][1]);
            textureIndex++;
        } else if (memcmp(p, "v", 1) == 0) {
            sscanf(p, "v %f %f %f", &vertexArray[vertexIndex][0], &vertexArray[vertexIndex][1], &vertexArray[vertexIndex][2]);
            vertexIndex++;
        } 
        while (*p++ != (char) 0x0A);
    }

}

Once the code hits the sscanf part, i get the exception:

Unhandled exception at 0x5e9cf2dc (msvcr100d.dll) in derp.exe: 0xC0000005: Access violation writing location 0xcccccccc.
  • 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-27T18:09:36+00:00Added an answer on May 27, 2026 at 6:09 pm

    As someone pointed out, you really shouldn’t be using triple pointers here.

    Additionally, you might want to do your file scanning as something other than chained if-blocks (or at least split it up into functions).

    This should fix your issue, since you only have 2 dereferences where you should have 3:

        if (memcmp(p, "vn", 2) == 0) {
            sscanf(p, "vn %f %f %f", &(*normalArray)[normalIndex][0], &(*normalArray)[normalIndex][1], &(*normalArray)[normalIndex][2]);
            normalIndex++;
        } else if (memcmp(p, "vt", 2) == 0) {
            sscanf(p, "vt %f %f", &(*textureArray)[textureIndex][0], &(*textureArray)[textureIndex][1]);
            textureIndex++;
        } else if (memcmp(p, "v", 1) == 0) {
            sscanf(p, "v %f %f %f", &(*vertexArray)[vertexIndex][0], &(*vertexArray)[vertexIndex][1], &(*vertexArray)[vertexIndex][2]);
            vertexIndex++;
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use std::vector for dynamically allocating memory. The scenario is: int neededLength
What are all the other things the new operator does other than allocating memory
Does String.ToLower() return the same reference (e.g. without allocating any new memory) if all
I'm having problems allocating and deallocating my memory in a recursive C++ program. So
I am currently trying to allocate the same amount of memory for a double
As a function argument I get a vector<double>& vec (an output vector, hence non-const)
These of 2 of the probably many ways of declaring arrays (and allocating memory
Can you explain what's going on with my code here? I'm not sure if
Supposed that for some reason you are only allowed to use static memory in
Looks like dynamic memory allocation without garbage collection is a way to disaster. Dangling

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.