0

I have a .dll c++ project created in visual studio 2017. And I have code in it that uses aws sdk to get files from s3 bucket.

I built this dll project on Debug mode mode and uses it on my main application (c++ also). And it worked.

Now i did make a release build of both dll project and my main application. And my application crashes when executing the "aws sdk c++" code.

Here's the code snippet about aws sdk c++:

    int Download()
    {
        Aws::SDKOptions options;
        Aws::InitAPI(options);
        {
            const Aws::String bucket_name = "timestamp-storage";
            //Aws::String key_name = "";
            const Aws::String region = "ap-northeast-1";
            std::map<int, std::string> uploadedBioMap = BiometricDB::List();
            std::map<int, std::string>::iterator i;
            for (i = uploadedBioMap.begin(); i != uploadedBioMap.end(); i++) {
                Aws::String key_name = i->second;
                std::cout << "Downloading " << key_name << " from S3 bucket: " <<
                    bucket_name << std::endl;
                Aws::Client::ClientConfiguration clientConfig;
                if (!region.empty())
                    clientConfig.region = region;
                Aws::S3::S3Client s3_client(clientConfig);
                Aws::S3::Model::GetObjectRequest object_request;
                object_request.WithBucket(bucket_name).WithKey(key_name);
                auto get_object_outcome = s3_client.GetObject(object_request);
                if (get_object_outcome.IsSuccess())
                {
                    Aws::OFStream local_file;
                    local_file.open(("enroll/" + key_name).c_str(), std::ios::out | std::ios::binary);
                    local_file << get_object_outcome.GetResult().GetBody().rdbuf();
                    std::cout << "Done!" << std::endl;
                }
                else
                {
                    std::cout << "GetObject error: " <<
                        get_object_outcome.GetError().GetExceptionName() << " " <<
                        get_object_outcome.GetError().GetMessage() << std::endl;
                }
            }
        }
        Aws::ShutdownAPI(options);
        return 1;
    }

Hope someone can help me.

noyruto88
  • 767
  • 2
  • 18
  • 40
  • If something works in a debug build but crashes in release (or works in release but crash in debug) it's typically a sign of *undefined behavior*. If you build a "release" version with debug information, does it crash as well? And if so, can you enter a debugger when the crash happens to locate it, and examine the involved variabled at that point? – Some programmer dude Jul 23 '19 at 06:10
  • just making a guess here : do you have the aws c++ sdk libraries built in 'release mode'? Probably the libraries/dependencies are built in debug mode so they work in debug mode so the release mode build of the libraries will be needed to make it work in release mode. – dorKKnight Jul 23 '19 at 06:42
  • I debug the released build and it shows the file that has an error, the "iosfwd" file with the exception thrown message about (vcruntime140.dll): Access violation writing location – noyruto88 Jul 23 '19 at 06:56
  • 1
    Where in ***your*** code does the crash happen? Please walk up the function call stack until you're are your code. – Some programmer dude Jul 23 '19 at 07:01
  • It stop after it execute this line of code "clientConfig.region = region;". I think that's where the error occur. – noyruto88 Jul 23 '19 at 07:39
  • That line of code is in the code snippet that I posted above. – noyruto88 Jul 23 '19 at 07:40
  • You say it reports an access violation; does it give an address for the location it tries to write to? – zenzelezz Jul 23 '19 at 08:25
  • Thank you guys for responding me. – noyruto88 Jul 24 '19 at 09:03

1 Answers1

0

By the way, nothings wrong with my code. I just found out that I need to update the nuget packages that I installed in visual studio. And so when i did, it solves the problem. Thank you.

noyruto88
  • 767
  • 2
  • 18
  • 40