Thread: Problem with Vectors And Pointers

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    Problem with Vectors And Pointers

    So heres the problem, we load our MS3D Model, we create a data structure array for each property, materials, vertices, physics, positions, etc etc...

    The problem is, that when the model doesn't have any material properties, and we push that back into the vector, it breaks, not when we push it back, thats no problem, but it seems it keeps pushing back some incredibly random number when material properties is nothing.

    Then when we try to render it, it breaks, because it is trying to look up an ID that essentially doesn't exist, some huge number like 34234698 or something silly like that...

    Should I create error materials? So when there is no material present it just loads an error material? Because vectors don't seem to enjoy pushing back empty pointers... If it would just push back the null pointer and return an ID of 0 when it is called, there would be no problem, but it seems to like adding a giant random number when this event occurs, breaking the program...

    What to dooo?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    >> but it seems it keeps pushing back some incredibly random number when material properties is nothing.

    If by nothing you mean 0 (in the sense nothing has been assigned to it) then make sure everything is initialised to a value when it's declared. Most of the time:

    Code:
    int i;
    i will simply be a random value - the value that was in memory before it was allocated is kept.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Oh, dur.. That probably is my problem..

    Make pointers null on creation would help too..

    Hmmm, I'll redo everything that way and see if I get better results..

    This system is the only thing seperating me from a fully managed rendered scene...

    and more artwork of course
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    Quote Originally Posted by Shamino
    Make pointers null on creation would help too..
    Uhh yea plz make sure those pointers are at least null or you are going to have some huge crashes later

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers and vectors
    By larne in forum C Programming
    Replies: 6
    Last Post: 09-12-2008, 10:27 AM
  2. Vectors using object pointers.
    By theJ89 in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2006, 10:29 PM
  3. Vectors of pointers and function templates
    By 7words in forum C++ Programming
    Replies: 3
    Last Post: 05-02-2004, 11:39 AM
  4. vectors of pointers
    By Myownworstenemy in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2003, 09:46 AM
  5. Vectors of pointers to objects
    By Myownworstenemy in forum C++ Programming
    Replies: 3
    Last Post: 09-01-2003, 11:23 PM