Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] Native Dialog, or path issue?

Credits go to Arthur Kalliokoski, Matthew Leverton, Todd Cope, and Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
[A5] Native Dialog, or path issue?
Spreggo
Member #12,514
January 2011

Hello,

I'm using 5.0.4, and al_get_native_file_dialog_path() seems to be returning 'const ALLEGRO_PATH *' when according to the documentation it should be returning 'const char'.

Attempting to use al_path_cstr() on the return of al_get_native_file_dialog_path() yields an access violation.

Here is my example:

#SelectExpand
1 2string filePath; 3 4 ALLEGRO_FILECHOOSER *fileDialog; 5 6 ALLEGRO_PATH *path; 7 8 path = al_create_path_for_directory( "/" ); 9 10 fileDialog = al_create_native_file_dialog( path, "Choose File...", "*.drp;*.cel", ALLEGRO_FILECHOOSER_SAVE); 11 12 al_show_native_file_dialog(display, fileDialog); 13 14 //if file selected 15 if( al_get_native_file_dialog_count(fileDialog) > 0 ) 16 { 17 filePath.clear(); 18//uncommenting the next line won't compile 19 //filePath = string( al_get_native_file_dialog_path(fileDialog, SIZE_MAX) ); 20 21//uncommenting the next line causes an access violation 22 //filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, SIZE_MAX), ALLEGRO_NATIVE_PATH_SEP ); 23 24 }

I'm probably doing something noobish, please advise.
???

Todd Cope
Member #998
November 2000
avatar

Make sure you have actually installed 5.0.4. The return type of al_get_native_file_dialog_path() was changed to const char * shortly before the 5.0.0 release.

Spreggo
Member #12,514
January 2011

I've ensured that 5.0.4 is installed, which did not solve the issue.

I'm using the windows builds (allegro-5.0.4-msvc-10.0.7z) from this thread: http://www.allegro.cc/forums/thread/608100

Are there any other low-hanging fruits I should investigate?

Trent Gamblin
Member #261
April 2000
avatar

What's the error message the compiler is giving you?

Spreggo
Member #12,514
January 2011

The violation when using "filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, SIZE_MAX), ALLEGRO_NATIVE_PATH_SEP );" is:

Unhandled exception at 0x5516b75b in Droplet.exe: 0xC0000005: Access violation reading location 0x0000001c.

When using "filePath = string( al_get_native_file_dialog_path(fileDialog, SIZE_MAX) );", the compiler says:

1>main.cpp(4117): error C2440: '<function-style-cast>' : cannot convert from 'const ALLEGRO_PATH *' to 'std::string'

Todd Cope
Member #998
November 2000
avatar

I see the error now. The second argument to al_get_native_file_dialog_path() is the path index. You need to use 0 for the second argument unless you are using the ALLEGRO_FILECHOOSER_MULTIPLE flag.

Spreggo
Member #12,514
January 2011

Unfortunately using "filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, 0 ), ALLEGRO_NATIVE_PATH_SEP );" instead yielded another access violation.

I've also noticed that no matter how I create the path, the native file dialog always opens the same directory. Even if I comment out 'path = al_create_path_for_directory( "/" );' the result is the same. It seems like this might possibly be related??

Thanks for the help everyone :)

Matthew Leverton
Supreme Loser
January 1999
avatar

Why should "/" work under Windows?

Arthur Kalliokoski
Second in Command
February 2005
avatar

Why should "/" work under Windows?

That stumped me for a couple minutes.

I think you need a drive letter, e.g. "C:/".

They all watch too much MSNBC... they get ideas.

Trent Gamblin
Member #261
April 2000
avatar

I think you've got some old headers still installed somewhere.

Spreggo
Member #12,514
January 2011

The only headers I have anywhere are the 5.0.4 ones from the archive I mentioned before.

As for the directory thing, I guess I'm ignorant on how to write it. I'm assuming that "C:/" would work, but using that doesn't change which directory the file dialog opens to.

I think I am going to start a fresh project to try out the file dialog in isolation and see what happens.

Edit: Not sure what is going on, but the forum won't allow me to reply to this thread now.

Here is the program I created to test the native file dialog:

#SelectExpand
1 2#include "stdafx.h" 3 4#include <string> 5 6#include <allegro5/allegro.h> 7#include <allegro5/allegro_native_dialog.h> 8#include <allegro5/path.h> 9 10 11ALLEGRO_DISPLAY *display; 12 13using namespace std; 14 15int main() 16{ 17 18 //Allegro set up 19 20 al_init(); //initiate allegro 5 21 22 display = al_create_display(800, 600); 23 24 25 //File dialog 26 27 string filePath; 28 29 ALLEGRO_FILECHOOSER *fileDialog; 30 31 ALLEGRO_PATH *path; 32 33 path = al_create_path_for_directory( "C:/" ); 34 35 fileDialog = al_create_native_file_dialog( path, "Choose File...", "*.*", ALLEGRO_FILECHOOSER_SAVE); 36 37 //Check if fileDialog successfully created... 38 if( fileDialog == NULL ) 39 { 40 fprintf( stderr, "Unable to create file dialog...\n" ); 41 } 42 43 al_show_native_file_dialog(display, fileDialog); 44 45 if( al_get_native_file_dialog_count(fileDialog) > 0 ) 46 { 47 48 filePath.clear(); 49 filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, 0), ALLEGRO_NATIVE_PATH_SEP ); 50 51 } 52 53 54 //clean up 55 56 al_destroy_native_file_dialog(fileDialog); 57 58 al_destroy_display(display); 59 60 return(0); 61}

This compiled but produces the following error:
Unhandled exception at 0x5daa1d39 in Native Dialog Test.exe: 0xC0000005: Access violation reading location 0x555c3a4b.

I'm at a loss really, since from what I understand, it shouldn't even compile...

Maybe someone could try compiling using the same libraries ( http://77.55.66.239/thedmd/allegro/5.0.4/allegro-5.0.4-msvc-10.0.7z ) and see if it reproduces?

Edit: Yep! I was doing something noobish. I looked high and low for old headers and couldn't find a thing. And then I realized that there were indeed old headers in the visual studio include folder. :-X

It works perfectly now, thank you all who tried to point me in the right direction from the start!

p.s. Also, the file path I was meaning to call should have been ".//" to get the program's directory in windows.

Go to: