www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.format doesn't want to work

reply solidstate1991 <laszloszeremi outlook.com> writes:
When I make this call
```
format(" %3.3f"w, avgFPS);
```
my program immediately crashes with an access violation error. 
The debugger out is different between x86 and x86-64.

I've made all sanity checks, so I need some other suggestions.
Oct 16 2021
next sibling parent frame <frame86 live.com> writes:
On Saturday, 16 October 2021 at 22:47:09 UTC, solidstate1991 
wrote:
 When I make this call
 ```
 format(" %3.3f"w, avgFPS);
 ```
 my program immediately crashes with an access violation error. 
 The debugger out is different between x86 and x86-64.

 I've made all sanity checks, so I need some other suggestions.
I think it would be helpful to know what type avgFPS is and what you do with the output of format(). Access violation is mostly an access to a null pointer.
Oct 16 2021
prev sibling next sibling parent reply russhy <russhy gmail.com> writes:
On Saturday, 16 October 2021 at 22:47:09 UTC, solidstate1991 
wrote:
 When I make this call
 ```
 format(" %3.3f"w, avgFPS);
 ```
 my program immediately crashes with an access violation error. 
 The debugger out is different between x86 and x86-64.

 I've made all sanity checks, so I need some other suggestions.
what is the type of avgFPS?
Oct 16 2021
parent reply solidstate1991 <laszloszeremi outlook.com> writes:
On Sunday, 17 October 2021 at 05:22:17 UTC, russhy wrote:
 On Saturday, 16 October 2021 at 22:47:09 UTC, solidstate1991 
 wrote:
 When I make this call
 ```
 format(" %3.3f"w, avgFPS);
 ```
 my program immediately crashes with an access violation error. 
 The debugger out is different between x86 and x86-64.

 I've made all sanity checks, so I need some other suggestions.
what is the type of avgFPS?
I's a double, but I've tried to pass it as real and float too, with the same exact error being generated.
Oct 17 2021
parent reply jfondren <julian.fondren gmail.com> writes:
On Sunday, 17 October 2021 at 12:53:07 UTC, solidstate1991 wrote:
 On Sunday, 17 October 2021 at 05:22:17 UTC, russhy wrote:
 On Saturday, 16 October 2021 at 22:47:09 UTC, solidstate1991 
 wrote:
 When I make this call
 ```
 format(" %3.3f"w, avgFPS);
 ```
 my program immediately crashes with an access violation 
 error. The debugger out is different between x86 and x86-64.

 I've made all sanity checks, so I need some other suggestions.
what is the type of avgFPS?
I's a double, but I've tried to pass it as real and float too, with the same exact error being generated.
then it's likely that some memory corruption prior to format() has broken the GC, and format's allocation of a string is what's failing. Try sprinkling ` safe` and and see what it complains about; try valgrind; try reducing your problem. I don't think we can help you more without a way to replicate the fault.
Oct 17 2021
parent solidstate1991 <laszloszeremi outlook.com> writes:
On Sunday, 17 October 2021 at 13:03:46 UTC, jfondren wrote:
 then it's likely that some memory corruption prior to format() 
 has broken the GC, and format's allocation of a string is 
 what's failing. Try sprinkling ` safe` and and see what it 
 complains about; try valgrind; try reducing your problem. I 
 don't think we can help you more without a way to replicate the 
 fault.
I ran Valgrind, and I've noticed some possible leakage in a library I've written, but I'll check for it further once I'll have a bit more time.
Oct 17 2021
prev sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 10/16/21 6:47 PM, solidstate1991 wrote:
 When I make this call
 ```
 format(" %3.3f"w, avgFPS);
 ```
 my program immediately crashes with an access violation error. The 
 debugger out is different between x86 and x86-64.
 
 I've made all sanity checks, so I need some other suggestions.
FYI, solidstate figured this out. It was because of an out-of-bounds index on `BitArray`. But that irks me. Why wouldn't `BitArray` do a bounds check? And then I remembered -- Phobos is built in release mode even when your app is not. I literally *cannot* request from the compiler that `BitArray` enforce its contracts without rebuilding the library completely. I never want to build code that doesn't have bounds checks. How can we fix this? -Steve
Oct 17 2021
parent reply user1234 <user1234 12.de> writes:
On Sunday, 17 October 2021 at 21:00:19 UTC, Steven Schveighoffer 
wrote:
 On 10/16/21 6:47 PM, solidstate1991 wrote:
 When I make this call
 ```
 format(" %3.3f"w, avgFPS);
 ```
 my program immediately crashes with an access violation error. 
 The debugger out is different between x86 and x86-64.
 
 I've made all sanity checks, so I need some other suggestions.
FYI, solidstate figured this out. It was because of an out-of-bounds index on `BitArray`. But that irks me. Why wouldn't `BitArray` do a bounds check? And then I remembered -- Phobos is built in release mode even when your app is not. I literally *cannot* request from the compiler that `BitArray` enforce its contracts without rebuilding the library completely. I never want to build code that doesn't have bounds checks. How can we fix this? -Steve
contracts ? bound checks should be in the body and conditionally compiled with `version(D_NoBoundsChecks){} else {}` then same problem because it's not a function template I guess. someone should make it a function template then.
Oct 18 2021
parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 10/18/21 8:35 AM, user1234 wrote:
 On Sunday, 17 October 2021 at 21:00:19 UTC, Steven Schveighoffer wrote:
 On 10/16/21 6:47 PM, solidstate1991 wrote:
 When I make this call
 ```
 format(" %3.3f"w, avgFPS);
 ```
 my program immediately crashes with an access violation error. The 
 debugger out is different between x86 and x86-64.

 I've made all sanity checks, so I need some other suggestions.
FYI, solidstate figured this out. It was because of an out-of-bounds index on `BitArray`. But that irks me. Why wouldn't `BitArray` do a bounds check? And then I remembered -- Phobos is built in release mode even when your app is not. I literally *cannot* request from the compiler that `BitArray` enforce its contracts without rebuilding the library completely. I never want to build code that doesn't have bounds checks. How can we fix this?
contracts ? bound checks should be in the body and conditionally compiled with `version(D_NoBoundsChecks){} else {}` then same problem because it's not a function template I guess. someone should make it a function template then.
Even a template may not help, if the compiler decides it's already been instantiated. -Steve
Oct 18 2021