Sign in to follow this  
Bear777

Unity Instances of class disappear.. (pointer problem?)

Recommended Posts

In short, I have a pointer problem. I make instances of a class in function 1, and when i point to those instances in function 2 the program crashes, while executing function 2 inside function 1 doesn't result in a crash. I think this has more to do with my lack of experience regarding C++ than a typical mistake.. but anwyay, the source code is of an open source planetary engine I'm working on, which I'm now redesigning to make it more suitable for the opensource community. See planet.h where it goes wrong, I commented it out. this is the link [Edited by - Bear777 on July 5, 2008 4:28:40 PM]

Share this post


Link to post
Share on other sites
" In short, I have a pointer problem. I make instances of a class in function 1, and when i point to those instances in function 2 the program crashes, while executing function 2 inside function 1 doesn't result in a crash. "

What comes to my mind just after reading those lines is,that you are instancing the classes in the local scope of the function1, and when function1 returns, the instances disappear from the memory, so the pointers in the function2 point to locations, which are containing some kind of nonsense and eventually lead to crash. When you call function2 in function1, the stack frame of the function1 is still there, and the pointers will work without any problem.

If you are instancing the classes in the function1 like that:

function1()
{
//some code...

classA A;
classB B;

//some other code...
}

try to change your code like that:

function1()
{
//some code...

classA* pA=new A;
classB* pB=new B;

//some other code...
}

The first code will create the class instances in the stack frame of the function1, these instances will be discarded after the function returns. The second code will create them on the heap, they won't be discarded unless you explicitly get rid of them with delete keyword. (like: delete pA, delete pB) Be sure to delete these after you used them, or you will run into memory leaks, which is the one of the most evil things on the mother earth. Try to match every "new" with a "delete".
Hope that helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by 67rtyus
" In short, I have a pointer problem. I make instances of a class in function 1, and when i point to those instances in function 2 the program crashes, while executing function 2 inside function 1 doesn't result in a crash. "

What comes to my mind
...
Hope that helps.


I am already doing it that way.

Quote:
Original post by dmatter
Quote:
Original post by Bear777
http://www.rocketsoft.gm-school.uni.cc/uploads/openPlanetary.rar << This is the link
That's an address, this is the link. [smile]


Thanks, I use forums which automatically make links too much.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
      628378
    • Total Posts
      2982334
  • Similar Content

    • By sveta_itseez3D
      itSeez3D, a leading developer of mobile 3d scanning software, announced today a new SDK for its automatic 3D avatar generation technology, Avatar SDK for Unity. The Avatar SDK for Unity is a robust plug-n-play toolset which enables developers and creatives to integrate realistic user-generated 3D avatars into their Unity-based applications. SDK users can allow players to create their own avatars in the application or integrate the SDK into their own production processes for character design and animation.
      “Virtual avatars have recently become increasingly popular, especially in sports games and social VR apps. With the advance of VR and AR, the demand to get humans into the digital world is only increasing”, said Victor Erukhimov, itSeez3D CEO. “Our new Avatar SDK for Unity makes it super-easy to bring the avatar technology into any Unity-based game or VR/AR experience. With the Avatar SDK for Unity now every developer can bring face scanning technology into their games and allow players to create their own personalized in-game avatars, making the gameplay much more exciting and immersive.”
      Key features of the Avatar SDK for Unity:
      Automatic generation of a color 3D face model from a single selfie photo in 5-10 seconds (!). Works best with selfies, but can be used with any portrait photo.
      Shape and texture of the head model are unique for each person, synthesized with a deep learning algorithm crafted by computer vision experts
      Head models support runtime blendshape facial animations (45 different expressions)
      Generated 3D heads include eyes, mouth, and teeth
      Algorithms synthesize 3D meshes in mid-poly resolution, ~12k vertices, and ~24k triangles
      Six predefined hairstyles with hair-recoloring feature (many more available on request)
      Avatar generation API can be used in design-time and in run-time, which means you can allow users to create their own avatars in your game
      Cloud version is cross-platform, and offline version currently works on PCs with 64-bit Windows (support for more platforms is coming soon)
      Well-documented samples showcasing the functionality.
       
      Availability
      The Avatar SDK for Unity is offered in two modes - “Cloud” and “Offline”. The “Cloud” version is available at http://avatarsdk.com/ and the “Offline” version is available by request at support@itseez3d.com.
      ###
      About itSeez3D
      At itSeez3D, we are working on the computer vision technology that turns mobile devices into powerful 3D scanners. itSeez3D has developed the world's first mobile 3D scanning application that allows to create high-resolution photorealistic 3D models of people's' faces, bodies and objects. The application is available for iOS and Windows OS mobile devices powered with 3D cameras. In 2016 the company introduced Avatar SDK that creates a realistic 3D model of a face from a single selfie photo. To learn more about itSeez3D scanning software and 3D avatar creation technology, please visit www.itseez3d.com and www.avatarsdk.com.

      View full story
  • Popular Now