Gwyddion is a modular program for scanning probe microscopy data visualization and analysis. I've been trying to use some of the libraries provided (in C++, and heavily Glib/gtk dependent) to load the proprietary file formats that are native to particular atomic microscope devices. The goal is to write a simple file conversion program using these libraries. I'm currently using Microsoft Visual Studio 2010 on a 64-bit Vista machine. I've run in to some difficulty that I've been unable to resolve as yet.
The relevant code is as follows:
Expand|Select|Wrap|Line Numbers
- int main(int argc, char *argv[])
- {
- /* Name of the file to display */
- const gchar *filename = argv[1];
- if(argc != 2){
- std::cout << "Usage: mi2bitmap <filename>" << std::endl;
- return 1;
- }
- /* Error Initialization */
- GError *err = NULL;
- /* The data file contents */
- GwyContainer *data = NULL;
- /* Initialize Gtk+ */
- gtk_init(&argc, &argv);
- /* Initialize Gwyddion stuff */
- gwy_app_init_common(&err, "layer", "file", NULL);
- /* Name of the file to export as */
- const gchar *extension = "jpeg";
- gchar *mpath = gwy_find_self_dir("");
- gchar *importfilenamefull = g_build_filename(mpath, "\\" , filename, NULL);
- gchar *exportfilenamefull = g_build_filename(mpath, "\\" , filename, ".", extension, NULL);
- gchar *gfilename = g_filename_to_utf8(gwy_canonicalize_path(importfilenamefull), -1, NULL, NULL, &err);
- gchar *gfilename_x = g_filename_from_utf8(gwy_canonicalize_path(exportfilenamefull), -1, NULL, NULL, &err);
- std::cout << gwy_file_detect(gfilename, TRUE, GWY_FILE_OPERATION_DETECT) << std::endl;
- /* Load the file */
- data = gwy_file_load(gfilename, GWY_RUN_NONINTERACTIVE, &err);
- if (!data) {
- std::cout << std::endl;
- g_printerr("File load error: Cannot load `%s': %s\n", argv[1], err->message);
- g_clear_error(&err);
- return 1;
- }
- /* Free Resources */
- g_free(&filename);
- g_free(mpath);
- g_free(err);
- g_free(gfilename);
- g_free(gfilename_x);
- g_free(exportfilenamefull);
- g_free(importfilenamefull);
- g_object_unref(data);
- return 0;
- }
If I comment out gwy_file_load, it seems that gwy_file_load fails, throwing the error " Cannot load `sample.mi': No module can load this file type." This failure persists for any file type I try. More telling though, is that gwy_detect_file will cause the program to crash with "Unhandled exception at 0x5ef3d540 (msvcr100d.dll) in mi2bitmap.exe: 0xC0000005: Access violation reading location 0x00000000." It seems as though I'm deferencing a null pointer somewhere, but the crash occurs with any value I set the first argument as in gwy_detect_file. The documentation for these file loading functions can be found here.
This is probably a bit of a long shot, as I suspect that few if any here are familiar with Gwyddion, but perhaps Glib/Gtk experience will help, and as a complete C++ beginner I'd appreciate any help I can get with this.
Thanks very much.
Edit: the debugger seems to indicate that the crash occurs at this line in the stack:
main_loop:
mov eax,dword ptr [ecx] ; read 4 bytes