Cross-platform SDK and HTML5 tools for mobile app development
X
 
7 posts / 0 new
Last post
Zoe
Zoe's picture
Offline
Mobile Conjurer
Joined: 23 Feb 2012
Posts:
Deleting Widgets

Hi

I've been having problems trying to delete native ui widgets.  I have a stackscreen with 2 screens.  When i want to move between the first screen to the second, i call a redraw function in the second screen which clears the widgets off the screen and rebuilds them (i will be linking a database into this so it will be pulling its data from there soon).

For a few attempts it seems fine to move between the first and second screens, and then it will crash.  No errors are appearing in mosync so i ran the project in xcode and and it returns EXC_BAD_ACCESS.  It seems to revolve around a function called free_ex.  Its not restricted to a single native ui widget type either so it seems more general issue.

Any help would be much appreciated.

Thanks

Zoe
Zoe's picture
Offline
Mobile Conjurer
Joined: 23 Feb 2012
Posts:
But i'm building for iphone,

But i'm building for iphone, not android (i think i failed to mention that earlier)

Ovidiu
ovidiu's picture
Offline
Mobile Sorcerer
Joined: 27 Jan 2011
Posts:
We reproduced the issue and

We reproduced the issue and we have a bug which you can follow here.

Thanks for pointing it out and have fun using MoSync.

Ovidiu
ovidiu's picture
Offline
Mobile Sorcerer
Joined: 27 Jan 2011
Posts:
Good to know :) (I also

Good to know :) (I also missed the xcode mentioning in your first post)

I'll check it asap

Zoe
Zoe's picture
Offline
Mobile Conjurer
Joined: 23 Feb 2012
Posts:
I've managed to narrow down

I've managed to narrow down the problem and it seems to just be affecting the native ui datapicker.

The code below has a stackscreen with 2 screens, when you click the button to go from the first to the second screen it deletes whatever widgets are in the layout so they can be replaced.  The button is replaced succesfully but the creation of a new date picker seems to cause problems - i create and delete the datepicker at the same time because it seems to prove there is something wrong with the declaration without having to add it to any layouts.  This does seem to be related in some way to the layout that is defined underneath - if you move the datepicker declaration and delete to after the layout  declaration, then everything seems to work fine.  If i put in any other type of widget instead of a datepicker then it works fine.  It doesnt seem to matter if its a layout as the second widget or something else - i tested with a button.

This does seem to be a rather specialised issue but i'm worried that it is a manifestation of something more major.

Thanks


#include <ma.h>                 // Syscalls
#include <MAUtil/String.h>        // C++ String class
#include <MAUtil/Moblet.h>        // Moblet class
#include <conprint.h>            // lprintfln for logging

#include <NativeUI/Widget.h>
#include <NativeUI/Widgets.h>// Include all widgets

using namespace MAUtil;
using namespace NativeUI;

class NativeUIMoblet : public Moblet, public ButtonListener {
public:

    NativeUIMoblet()
    {
        stack = new StackScreen();

        screen1 = new Screen();
        button1 = new Button();
        button1->setText("button1");
        button1->addButtonListener(this);
        screen1->setMainWidget(button1);

        screen2 = new Screen();
        button2 = new Button();
        button2->setText("back");
        button2->addButtonListener(this);

        VerticalLayout* layout = new VerticalLayout();

        mainLayout = new VerticalLayout();
        mainLayout->wrapContentVertically();
        mainLayout->addChild(button2);
        mainLayout->addChild(layout);
        screen2->setMainWidget(mainLayout);

        stack->push(screen1);
        stack->show();
    }

    void NativeUIMoblet::buttonClicked(Widget* button) {
        if(button == button2) {
            stack->pop();
        }
        else {
            int widgets = mainLayout->countChildWidgets();

            for(int i=0; i<widgets; i++) {
                Widget* temp = mainLayout->getChild(0);
                mainLayout->removeChild(temp);
                delete temp;
            }

            button2 = new Button();
            button2->setText("back");
            button2->addButtonListener(this);

            DatePicker* date = new DatePicker();
            delete date;
            date = NULL;

            VerticalLayout* layout = new VerticalLayout();

            mainLayout->addChild(button2);
            mainLayout->addChild(layout);

            stack->push(screen2);
        }
    }

    virtual ~NativeUIMoblet(){}

private:
    Screen* screen1;
    Screen* screen2;
    Button* button1;
    Button* button2;
    StackScreen* stack;
    VerticalLayout* mainLayout;
};

extern "C" int MAMain(){
    NativeUIMoblet* moblet = new NativeUIMoblet();
    Moblet::run(moblet);
    delete moblet;
    return 0;
}

Ovidiu
ovidiu's picture
Offline
Mobile Sorcerer
Joined: 27 Jan 2011
Posts:
The issue I could see in the

The issue I could see in the log is

I/MoSync  (  419): initCompatibility mDatePicker_setMaxDate fail
I/MoSync  (  419): initCompatibility mDatePicker_setMinDate fail
I/MoSync  (  419): initCompatibility mDatePicker_getMaxDate fail
I/MoSync  (  419): initCompatibility mDatePicker_getMinDate fail

However this is not an error or a problem: the four methods are just not available in the current Android version and what you see is the result of the java reflection mechanism we used. When these methods will become available in newer Android versions, we won't have to do anything in mosync and you'll have access to them (and no "error" message will appear).

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:
Hmm, I've not come across

Hmm, I've not come across this.  Are you using the NativeUI C++ library or C?  Can you share some code?

Login or register to post comments