Thread: std::unique_ptr going out of scope causes access violation?

  1. #1
    Registered User Chris87's Avatar
    Join Date
    Dec 2007
    Posts
    129

    std::unique_ptr going out of scope causes access violation?

    I've been trying to make a plugin for Assimp for a while now, and for the most part, it works until the end of the function, which by then an exception is thrown about the std::unique_ptr variable I used. I compared its use to other plugins and I'm... baffled. It seems to be okay, I thought?

    My apparently faulty std::unique_ptr: assimp/ISM2Loader.cpp at master * NebuHiiEjamu/assimp * GitHub

    Working code with unique_ptr by someone else: assimp/ASELoader.cpp at master * NebuHiiEjamu/assimp * GitHub

  2. #2
    Registered User john.c's Avatar
    Join Date
    Dec 2017
    Posts
    356
    Presumably the pointer that pIoHander->Open() returns should not be deleted, so a unique_ptr doesn't apply here.
    If you were just using a regular pointer would you call delete on it at the end of the function? I suspect not.
    E.g., in C we don't free a FILE* at the end of a function.
    Simplicity is the ultimate sophistication.

  3. #3
    Registered User Chris87's Avatar
    Join Date
    Dec 2007
    Posts
    129
    Hmm... I'll give it a try with a regular pointer. Not sure how ASELoader uses it differently though... Maybe I'm supposed to close it

  4. #4
    Registered User john.c's Avatar
    Join Date
    Dec 2017
    Posts
    356
    I didn't look at the other code last time. Now that I look, I wonder if perhaps that code is also making a mistake and just getting "lucky" (or not, depeding on how you look at it).


    I would read up on exactly how those classes (IOHandler and IOStream) are supposed to be used. You probably do have to close it.
    Simplicity is the ultimate sophistication.

  5. #5
    Registered User Chris87's Avatar
    Join Date
    Dec 2007
    Posts
    129
    That's certainly awkward, but yeah I'll look. Thanks

  6. #6
    Registered User john.c's Avatar
    Join Date
    Dec 2017
    Posts
    356
    Just try opening with:
    Code:
    IOStream *io = pIOHandler->Open(pFile.c_str(), "rb");
    and closing it with
    Code:
    pIOHandler->Close(io);
    Have you tried running the other code? Does it seem to run properly?

    EDIT:
    I looked at the documentation, and it seems like your original code should probably have worked. I don't know what's going on.

    Assimp: Assimp::IOSystem Class Reference

    Assimp: Assimp::IOStream Class Reference
    Last edited by john.c; 05-15-2018 at 04:44 PM.
    Simplicity is the ultimate sophistication.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Access Violation
    By jonesk1978 in forum C++ Programming
    Replies: 6
    Last Post: 03-29-2012, 08:23 PM
  2. Access violation
    By juice in forum C Programming
    Replies: 8
    Last Post: 03-10-2012, 10:32 AM
  3. Access Violation
    By Graham Aker in forum C Programming
    Replies: 100
    Last Post: 01-26-2009, 08:31 PM
  4. Access Violation under VC++ 6.0
    By xephyr in forum C Programming
    Replies: 4
    Last Post: 07-30-2004, 12:06 AM
  5. Access Violation!!
    By Yoshi in forum C++ Programming
    Replies: 4
    Last Post: 09-11-2002, 01:22 PM

Tags for this Thread