A program built with makefile (mingw32) runs, but when built in IDE it crashes

0

I used msys64 - mingw32 (on Windows 7, 64 bit) to build a 3rd party library (libosmscout) using a supplied makefile. I was primarily interested in one particular example from the library (Demos/src/DrawMapCairo). With makefile complete library was built successfuly, including demos. Example console application of interest works fine.

My intention however is to make my own application using Code::Blocks IDE, which would use functionality of the example app. Therefore I tried to build the example in Code::Blocks (New project -> console application, GCC 5.1 MinGW). After a while I managed to get a successful build with 0 errors/warnings. But the application doesn't work, it crashes with sigsegv fault. "cout debugging" and stepping into in debugger suggest that the issue seems to be (or start) at line

osmscout::DatabaseRef database(new osmscout::Database(databaseParameter));

Source code with main() :

#includes...
static const double DPI=96.0;

int main(int argc, char* argv[])    
{
  std::string   map;
  std::string   style;
  std::string   output;
  size_t        width,height;
  double        lon,lat,zoom;


  if (argc!=9) {
    std::cerr << "DrawMap <map directory> <style-file> <width> <height> <lon> <lat> <zoom> <output>" << std::endl;
    return 1;
  }    

  map=argv[1];
  style=argv[2];     

  //next 6 lines not exactly as in source, but for shorter code:
  osmscout::StringToNumber(argv[3],width);    
  osmscout::StringToNumber(argv[4],height);
  sscanf(argv[5],"%lf",&lon);
  sscanf(argv[6],"%lf",&lat);
  sscanf(argv[7],"%lf",&zoom);    
  output=argv[8];

  osmscout::DatabaseParameter databaseParameter;
  osmscout::DatabaseRef       database(new osmscout::Database(databaseParameter));
  osmscout::MapServiceRef     mapService(new osmscout::MapService(database));

  if (!database->Open(map.c_str())) {
    std::cerr << "Cannot open database" << std::endl;

    return 1;
  }

  osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig (database->GetTypeConfig()));

  if (!styleConfig->Load(style)) {
    std::cerr << "Cannot open style" << std::endl;
  }

  cairo_surface_t *surface;
  cairo_t         *cairo;

  surface=cairo_image_surface_create(CAIRO_FORMAT_RGB24,width,height);

  if (surface!=NULL) {
    cairo=cairo_create(surface);

    if (cairo!=NULL) {
      osmscout::MercatorProjection  projection;
      osmscout::MapParameter        drawParameter;
      osmscout::AreaSearchParameter searchParameter;
      osmscout::MapData             data;
      osmscout::MapPainterCairo     painter(styleConfig);

      drawParameter.SetFontSize(3.0);

      projection.Set(lon,
                     lat,
                     osmscout::Magnification(zoom),
                     DPI,
                     width,
                     height);

      std::list<osmscout::TileRef> tiles;

      mapService->LookupTiles(projection,tiles);
      mapService->LoadMissingTileData(searchParameter,*styleConfig,tiles);
      mapService->ConvertTilesToMapData(tiles,data);

      if (painter.DrawMap(projection,
                          drawParameter,
                          data,
                          cairo)) {
        if (cairo_surface_write_to_png(surface,output.c_str())!=CAIRO_STATUS_SUCCESS) {
          std::cerr << "Cannot write PNG" << std::endl;
        }
      }

      cairo_destroy(cairo);
    }
    else {
      std::cerr << "Cannot create cairo cairo" << std::endl;
    }

    cairo_surface_destroy(surface);
  }
  else {
    std::cerr << "Cannot create cairo surface" << std::endl;
  }

  return 0;
}

How can I find exactly what the problem is and solve it? What's really puzzling me is that the same code built with makefile works just fine.


EDIT:

After running GDB (Gnu Debugger, gdb32.exe) and then bt (backtrace) I get the following output:

[New Thread 3900.0x538]

Program received signal SIGSEGV, Segmentation fault.
0x777ec159 in ntdll!RtlDecodeSystemPointer ()
   from C:\Windows\SysWOW64\ntdll.dll
(gdb)


(gdb) bt
#0  0x777e3c28 in ntdll!RtlQueryPerformanceCounter ()
   from C:\Windows\SysWOW64\ntdll.dll
#1  0x00000028 in ?? ()
#2  0x00870000 in ?? ()
#3  0x777ec1ed in ntdll!RtlDecodeSystemPointer ()
   from C:\Windows\SysWOW64\ntdll.dll
#4  0x777ec13e in ntdll!RtlDecodeSystemPointer ()
   from C:\Windows\SysWOW64\ntdll.dll
#5  0x777e3541 in ntdll!RtlQueryPerformanceCounter ()
   from C:\Windows\SysWOW64\ntdll.dll
#6  0x00000010 in ?? ()
#7  0x00000028 in ?? ()
#8  0x008700c4 in ?? ()
#9  0x77881dd3 in ntdll!RtlpNtEnumerateSubKey ()
   from C:\Windows\SysWOW64\ntdll.dll
#10 0x7783b586 in ntdll!RtlUlonglongByteSwap ()
   from C:\Windows\SysWOW64\ntdll.dll
#11 0x00870000 in ?? ()
#12 0x777e3541 in ntdll!RtlQueryPerformanceCounter ()
   from C:\Windows\SysWOW64\ntdll.dll
#13 0x00000010 in ?? ()
#14 0x00000000 in ?? ()
(gdb)

What does this error mean and how to find what caused it to correct the fault?

c++
codeblocks
openstreetmap
segmentation-fault
asked on Stack Overflow Apr 5, 2016 by James C • edited Apr 7, 2016 by James C

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0