Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.


Size calculations

  • Arjan Somers
    Arjan Somers


    I am still trying to get sizes of different elements.

    I am using the method from the memory test example, to do a rendering without creating a window.
    (The method is also described in:\)

    It all seem to work but every once in a while the returned values are incorrect. In those cases the position is wrong, and the width and height is 0.

    It seems the error is quite random, because is i run the same test several times, the result are usually correct, but once every couple times the results are wrong.

    There are no error messages that can help so a am quite clueless why this happens.

    I tried several things like adding a Threadh.sleep() after the invokeAndWait, because it the only thing i could think of that could create this random error is that the drawing thread is not finished, but that didn't help.

    I hope you've got any idea how to fix it.

    • What I suspect is happening is that you're obtaining the sizes outside of the GUI thread. Rendering (which sets the sizes of renderer nodes) occurs in the GUI thread.

    • Arjan Somers
      Arjan Somers

      I am not using a GUI thread, but i call a render directly in the same way as it's done in the memory test (I wan't to do an off-screen render). Is this incorrect?

    • Arjan Somers
      Arjan Somers

      I would really like to resole this issue, so i can use cobra in an production enviroment.
      So i'll try to explain some more and i hope you can help me.

      My main goal is to find the size and position of different elements like pictures or the entire page. I do not want to display the rendering, i only need the values.

      As suggested in another thread on this forum i used some code from the "testRendererLoop" function from "" to start the render, and after that i do

      HTMLImageElementImpl image = (HTMLImageElementImpl)images.item(j); 
      if (image.getSrc().equals(imageUrl))
          UINode uinode = image.getUINode(); 
          BoundableRenderable br = (BoundableRenderable) uinode;
          Point guiPoint = br.getGUIPoint(0, 0);
          return new Size(guiPoint.x, guiPoint.y, image.getWidth(), image.getHeight());

      This seems to work most of the time but sometimes the results are wrong as explained in the first post.

      I hope you can point me in the right direction with this extra info.

      Thanks in advance for you time.

    • Arjan Somers
      Arjan Somers


      I have another update. It seems i may have found the error (partially). I was testing the code on a slow laptop on a large dataset using a lot of threads to do the parsing. And it seems this is somehow related to the error. When i limit the amount of threads the amount of errors reduces a lot.

      I still don't know why the errors occur. But at least the amount of errors is reduced.
      I'll post more info if i find anything interesting.

    • The rendering logic assumes it's done in a single thread (typically the GUI thread). I suppose you could also synchronize around the rendering.

      That's the case, unless you have a different root RBlock instance for every thread.

      If that's not the problem, maybe you can open a bug report with some code that reproduces.