1

I compiled the program below in debug mode without any error. I could run .exe file from the command line but when I try to debug code inside visual studio the exception gets thrown from the line

DetectionInternalSettings* internal_settings =
           DetectionInternalSettingsFactory::createFromFileSystem(
                  "C:/data/card_detection_engine.yaml");

Anyone who faced this situation before where behavior is different running from command line and in debug mode.

int main(int argc, char **argv) 
{
    DetectionSettings settings;
    try
    {
        DetectionInternalSettings* internal_settings =
        DetectionInternalSettingsFactory::createFromFileSystem("../data/card_detection_engine.yaml");
    }
    catch (const MyException &e)
    {
        fprintf(stderr, "Exception raised: %s\n", e.what().c_str());
        return 1;
    }

    return 0;
}

I also went into the exception details and here it is First-chance exception at 0x76E1C41F in ocrcarddetectionengine_sample.exe: Microsoft C++ exception: YAML::TypedBadConversion at memory location 0x003FF0D0.

More code related to createFromFileSystem

DetectionInternalSettingsFactory::createFromFileSystem(const std::string &configPath)  throw (MyException)
{
  return new DetectionInternalSettingsImpl(configPath);
}

struct DetectionInternalSettingsImpl : public DetectionInternalSettings {
    DetectionInternalSettingsImpl(const std::string &config_path) {
        if (config.ReadFromFilesystem(config_path)) {
            throw MyException("Bad configuration path.");
        }
    }

    ~DetectionInternalSettingsImpl() { }

    Core::Detector::Configuration config;
};
vkaul11
  • 4,098
  • 12
  • 47
  • 79
  • Show us `createFromFileSystem` and tell us what the exception is... – Ed S. Aug 09 '13 at 22:00
  • 1
    Running a program from the command line vs the IDE, you have different heaps, and different CWDs. I suspect the CWD is the issue. – Mooing Duck Aug 09 '13 at 22:04
  • Ed S. I have put more code in the question above – vkaul11 Aug 09 '13 at 22:18
  • Are you linking to an outside library ? Have you tweaked Visual Studio's project configuration parameters between your last complete Make process and the last partial compilation ? – Benoît Aug 09 '13 at 22:33
  • the exception comes from config.ReadFromFilesystem, and it is YAML::TypedBadConversion - have you debugged into ReadFromFilesystem to see where the exception raised? it is probably type conversion error as http://stackoverflow.com/questions/12374691/yaml-cpp-easiest-way-to-iterate-through-a-map-with-undefined-values suggests – Baiyan Huang Aug 09 '13 at 22:41
  • But why is not happening when I run from command line. I even reads out the contents of the yaml correctly and then processes that input. – vkaul11 Aug 09 '13 at 22:51
  • That is yet to be figured out - as @MooingDuck mentioned, it might be the CWD, it might be the parameters you configured in VS for debugging. Since you have the code, and you know the exception, why not start debugging as a start - then maybe we will have a better idea. – Baiyan Huang Aug 09 '13 at 22:57
  • Yes it was the CWD guys. Thanks for your help. – vkaul11 Aug 09 '13 at 23:36
  • @vkaul11 good to know you fixed it - could you explain a bit how CWD cause the YAML::TypedBadConversion? thanks – Baiyan Huang Aug 10 '13 at 00:10
  • The problem was that "../data/card_detection_engine.yaml" does not seem to not pick the right path "../data/card_detection_engine.yaml" when run from the debugger but when I run the .exe from command line it uses the right project directory. Therefore I used "C:/data/card_detection_engine.yaml" to give the absolute path, but even that failed with the debugger. That was fixed with "C://data//card_detection_engine.yaml" double slash. – vkaul11 Aug 11 '13 at 17:09

1 Answers1

0

Trust the debug mode exception. It is testing more thoroughly what your code is actually doing while the command line is simply waiting for problems to happen.

In your case, they don't seem to happen, probably because you're not doing anything with the pointer variable.

Benoît
  • 16,798
  • 8
  • 46
  • 66