Thread overview
Writing to file problem (Kernelbase exeption)
Jun 05, 2014
Konrad
Jun 05, 2014
Kagamin
Jun 05, 2014
Konrad
Jun 05, 2014
Stefan Koch
Jun 05, 2014
Konrad
Jun 05, 2014
Ali Çehreli
Jun 05, 2014
Konrad
June 05, 2014
Hi guys!
I have problem with writing to a file.
My function looks like this:
[code]
int game_change_config(string _player_spritesheet, string _flame_spritesheet) {
   string info = _player_spritesheet~"\n"~_flame_spritesheet;
   auto config_file = File("Data/config.ini");
   config_file.write(info);	
   return 0;
}[/code]

Everythings compile just fine, but sadly I'm getting Kernelbase.dll exception while function is running.
Could you help me that problem? :)

Best regards,
Ironus

PS. I'm sorry for my poor english.
June 05, 2014
Try to reduce it: remove code from the program piece by piece until you find a fragment, which causes the problem.
June 05, 2014
Well, there is a problem with
config_file.write(info);

but when I'm changing it to
write("Data/config.ini", info);
(as it states in http://dlang.org/phobos/std_file.html#.write) I'm getting an error of conflict between std.stdio.write and std.file.write. That's why I was using the first line.

Is there any way to solve this problem?

Best regards,
Ironus
June 05, 2014
config_file needs to be the string
not a struct File
.
June 05, 2014
Right now I have:

import file = std.file;
import std.stdio;

int game_change_config(string _player_spritesheet, string _flame_spritesheet) {
   string info = _player_spritesheet~"\n"~_flame_spritesheet;
   char[] info_table;
   for(int i = 0; i < info.length; i++) {
      info_table.length++;
      info_table[info_table.length - 1] = info[i];
   }
   file.write("Data/config.ini", info_table);	
   return 0;
}

I'm changing my string into dynamic char array and I'm using "Data/config.ini" as a string, just as Stefan Koch suggested. Everything compiles and my function doesn't return any errors while working, but it's not changing my file content (it's still as same as before running a function).

Any solutions? I'm starting to get pretty angry about that problem (more complicated stuff is working fine and that one part can't)...

Best regards,
Ironus
June 05, 2014
On 06/05/2014 01:39 PM, Konrad wrote:> Right now I have:
>
> import file = std.file;
> import std.stdio;
>
> int game_change_config(string _player_spritesheet, string
> _flame_spritesheet) {
>     string info = _player_spritesheet~"\n"~_flame_spritesheet;
>     char[] info_table;
>     for(int i = 0; i < info.length; i++) {
>        info_table.length++;
>        info_table[info_table.length - 1] = info[i];

That is not necessary, a simple concatenation would be the equivalent:

    info_table ~= info[i];    // instead of the previous two lines

>     }
>     file.write("Data/config.ini", info_table);

Random guess: Try with full path and see whether that helps. How about file access rights? Can you write to that file by other means?

Ali

June 05, 2014
Ok, I have rebuilded whole solution in MSVS (I'm using VisualD plugin) and everything started to work with my previously pasted code.

@Ali, thank you for advise with concatenation, I haven't thought about that.

Also thank you to all of you, guys, all that you wrote was very helpfull.

Best regards,
Ironus