Ever want to compile D on your Android phone? Well, now you can!

Steven Schveighoffer via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Nov 1 06:33:02 PDT 2016


On 10/29/16 8:55 PM, rikki cattermole wrote:
> On 30/10/2016 10:47 AM, Mergul wrote:
>> Application always crash when I'm using android_app.savedState.
>>
>> if (state.savedState != null) {
>>     // We are starting with a previous saved state; restore from it.
>>     engine.state = *cast(saved_state*)state.savedState; //crash!
>> }
>>
>
> Don't compare against null using =, compare using is.
>
> if (state.savedState !is null) {

android_app.savedState appears to be defined here:

https://github.com/joakim-noah/android/blob/polish/android_native_app_glue.d#L56

It's a void *. So comparing against null with != is identical to !is.

There are actually cases where comparing against null with != is valid, 
and what you want exactly (e.g. comparing a string to null to check for 
empty string).

In this case, fixing the comparison is not the answer. What is happening 
is one of several things:

1. I don't know what type `engine` is, so if it's a pointer, then 
dereferencing the state member may be the culprit if engine is invalid.
2. If state is a pointer, then you could be crashing at the if statement 
(unlikely).
3. state or state.savedState isn't being properly initialized.
4. Something else (e.g. code generation error). Hope it's not this one.

-Steve


More information about the Digitalmars-d-announce mailing list