Jump to content
  • Advertisement
Sign in to follow this  

Mesh cloned with Mesh.Clone gets disposed when original mesh gets disposed

This topic is 4441 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to texture a sphere and have figured out that I need to create a shpere, clone it with texture parameters and then set the necessary. So I'm currently using some of ZMans code (tut 5 I think it was) however when I come to draw the mesh I get an exception - Object reference not set to an instance of an object - on the sphere.DrawSubset call. Examining the sphere object shows that it has been disposed (Dispose = true). So going back to the creation step, I've narrowed it down to the below code:
        public Mesh CreateTexturedSphere(Device device, float radius, int slices, int stacks)
            Mesh nonTexturedMesh = Mesh.Sphere(device, radius, slices, stacks);
            Mesh m = nonTexturedMesh.Clone(nonTexturedMesh.Options.Value, nonTexturedMesh.VertexFormat | VertexFormats.Texture1, nonTexturedMesh.Device);


            return m;
When I do the nonTexturedMesh.Dispose(); call, my cloned mesh also gets disposed at this point! Whats even wierder, if I change the device used in the Clone to the device passed in, it works (even though that device is what the nonTexturedSphere was created with). Running though ZMans code (built in the same environment), then all works fine. Can any one shed any light on this behaviour? Have I missed out some state flag that somehow links things together? Cheers

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!