wei-spring / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

scaledWidth is returning null #1359

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

What version of the product are you using? On what operating system?
iPad Mini iOS 8.1.1

Please provide any additional information below.

scaledWidth is returning null in iOS in recent builds, in both new and old vm. 
Few days ago was fine but now I am finding this problem. The method works fine 
in Andoid devices and simulator.

Test case:

package com.Test;

import com.codename1.io.ConnectionRequest;
import com.codename1.io.NetworkManager;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Image;
import com.codename1.ui.Label;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import java.io.IOException;
import java.io.InputStream;

public class MyApplication {

    private Form current;
    private Image imagen;

    public void init(Object context) {
        try {
            Resources theme = Resources.openLayered("/theme");
            UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
        } catch(IOException e){
            e.printStackTrace();
        }
    }

    public void start() {
        if(current != null){
            current.show();
            return;

        }  
        final Form hi = new Form("Hi World");             
        ConnectionRequest cr = new ConnectionRequest() {
            @Override
            protected void readResponse(InputStream input) throws IOException {
                imagen = Image.createImage(input);
            }

            @Override
            protected void postResponse() {
                hi.addComponent(new Label(imagen)); // No problem
                imagen = imagen.scaledWidth(100); // Null in muy iPad
                hi.addComponent(new Label(imagen));                
                hi.revalidate();
            }            
        };
        cr.setPost(false);
        cr.setUrl("http://www.codenameone.com/files/theme/logo.png");
        NetworkManager.getInstance().addToQueue(cr);        
        hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        hi.show();        
    }

    public void stop() {
        current = Display.getInstance().getCurrent();
    }

    public void destroy() {
    }
}

Original issue reported on code.google.com by cverd...@gmail.com on 17 Feb 2015 at 2:21

GoogleCodeExporter commented 9 years ago
There is also a problem with scaledHeight().

Example Code:
public void start()
{
    if (current != null) {
        current.show();
        return;
    }

        Form hi = new Form("Hi World");

    Image vImage = theme.getImage("icon.png");
    vImage = vImage.scaledHeight(64);

        hi.addComponent(new Label("Hi World"));
        hi.addComponent(new Label(vImage));

    hi.show();
}

The above code generated the following stack trace.
 <Warning>: java.lang.NullPointerException
        at java_util_Hashtable.get:471
        at com_codename1_impl_ios_IOSImplementation.extractHardRef:2130
        at com_codename1_ui_Display.extractHardRef:2852
        at com_codename1_ui_Image.getCachedImage:94
        at com_codename1_ui_Image.scaledImpl:916
        at com_codename1_ui_Image.scaled:896
        at com_codename1_ui_Image.scaledHeight:847
        at com_codename1_ui_EncodedImage.scaledHeight:542
        at org_tradeswitch_mobile_MyApplication.start:38
        at org_tradeswitch_mobile_MyApplicationStub.run:27
        at com_codename1_ui_Display.processSerialCalls:1116
        at com_codename1_ui_Display.mainEDTLoop:938
        at com_codename1_ui_RunnableWrapper.run:120
        at com_codename1_impl_CodenameOneThread.run:176
        at java_lang_Thread.runImpl:153

Original comment by eddie.ca...@gmail.com on 17 Feb 2015 at 6:41

GoogleCodeExporter commented 9 years ago
Thanks, turns out it wasn't the VM but rather an API bug due to a thread safety 
change.

Original comment by shai.almog on 17 Feb 2015 at 7:52