Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
Posts: 76
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile
Accepted Solution

Crash on setVisible method

I've got this crash but i can't figure out why. The debugger doesn't help much:

 

Thread [1] (STOPPED) (Suspended : Signal : SIGSEGVSmiley Frustratedegmentation fault)    
    0x7949fff8    
    0x794a1ba6    
    0x794a1ba6    

The setVisible is called on a Label * object that is allocated in the constructor of the class that owns this field. The method where the crash happens is a slot method. The slot method is called by a connection with a specific class signal. The strange thing is that the first time that the signal is emitted and the slot method is called there are no crash at all. However the second time that the method is called the method crash on the first line where the setVisible take place.

 

void MyClass::update()

{

     ...

    emit doUpdate();

    ...

}

 

void MyClass::doUpdate()

{

    MyLabel->setVisible(false);

    ...

}

 

The first time the function is called from a slot method of class ClassA and the second time from slot method of class ClassB. Both of these classes have the same reference to the object of class MyClass.

void ClassA::methodA()

{

    ...

    MyClassObject->update();

    ...

}

 

void ClassB::methodB()

{

    ...

    MyClassObject->update();

    ...

}


I know that graphic object cannot be updated from an external thread but here I call only the emit from a perhaps different thread.

Any help is appreciated.
 

 

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Crash on setVisible method

[ Edited ]

Can you post the code where you instantiate the Label as well.

 

When you set a breapoint on that line the second time around was the pointer valid?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Regular Contributor
Posts: 76
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Crash on setVisible method

[ Edited ]

Thank you.
This is the initialization:

 

    MyLabel = new Label();
    MyLabel->setHorizontalAlignment(HorizontalAlignment::Fill);
    MyLabel->setVerticalAlignment(VerticalAlignment::Fill);
    MyLabel->textStyle()->setColor(Color::White);
    MyLabel->setText("Tentativi disponibili: X");
    MyLabel->setVisible(false);

 I forgot to say that there is another slot method that set the lable to visible before I call the update() method:

void MyClass::update2()

{

     ...

    emit doUpdate2();

    ...

}

 

void MyClass::doUpdate2()

{

    MyLabel->setVisible(true);

    ...

}


So i call update2() to show the label and then i set update() to hide the label. I do that to avoid the recreation of the whole Container object every time but i guess that this could be a workaround.

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Crash on setVisible method

Please post the entire .h / .cpp. The code you posted looks correct.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Crash on setVisible method

... and checking the validity of the pointer on the second method call?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Regular Contributor
Posts: 76
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Crash on setVisible method

[ Edited ]

I'm sorry I can't post the code because my company doesn't allow me to do that.

 

I checked the Variable with the debug visual of Momentics and and It seem to be NULL.
That's a very strange because I can see in front of me the Label and indeed the variable it's allocated in the constructor. It seems like to be freed or somithing like that.

The problem seems to be related the path: setVisible(false) - setVisible(true) - setVisible(false).

 

Can I do more then 2 switch from true to false and vice-versa ?

I add the component to the container but I set the Visibility to false. Then I show up the label and when some operations are finished I try to hide the label but it fail becouse of the NULL pointer.

Is an object freed when setVisible(false) is called ?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Crash on setVisible method

It won't be the setVisible() you can do that as many times as you like, somewhere else in your code you are either setting it to null or deleting the object.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Crash on setVisible method

Without the code you are going to have to step through the code yourself watching for when the pointer changes.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Crash on setVisible method

BBSJdev is correct. The label has most likely been destroyed or was never instantiated.

Regular Contributor
Posts: 76
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Crash on setVisible method

The variable was actually NULL but because another instance of the class MyClass was wrongly called using a different flow and the variable was wrongly unitialized.

 

I found another issue with a wrong usage of app->setScene method. I now use this method only on the first page of the app an the page switch is made using a NavigationPane rather than setting the new Page.

 

app->setScene(Page) //Only on the first page
app->setScene(NavigationPane) //On the next pages

I have wrongly used the setScene method to switch to a page then switching to another an then switching back to the first page. I read in the documentation that the setScene method destroy the previus graphical object, this is why I started using the NavigationPane more precisely:

...If the replaced scene (if one was set) is owned by the Application it will be deleted...

 I think this mean that the memory is freed and the Page is no longer available to rendering.