A bug in Widget’s Window picker

Yesterday, I experienced a segmentation fault in my application. After done a series of debugging that also made me compile the OpenSceneGraph (ver 2.6.1) in Debug mode, I figured out that the segmentation fault was caused from a method call from a NULL object.

The bug was in pickAtXY method of WindowManager class that is declared in WindowManager.cpp. The problematic code was like this.

if(
    (!win || win->getVisibilityMode() == Window::VM_PARTIAL) &&
        !win->isPointerXYWithinVisible(x, y)
) continue;

Spot the problem? What if win is NULL? It should proceed to continue immediately and don’t make any call to its method. But in the above code, a NULL win would still make its isPointerXYWithinVisible() called.

The fix should be trivial. But before I made my own modification, I decided to look at the latest version of OpenSceneGraph (2.8.0 rc3) and, guess what, it is already fixed! So I only had to copy the bug-free version and pasted it to the ver 2.6.1 code that I use. The new code is like the following.

if(
    !win ||
        (win->getVisibilityMode() == Window::VM_PARTIAL && !win->isPointerXYWithinVisible(x, y))
) {
    continue;
}

Just swapping some parentheses and the bug is gone!

You know what, this is why I like working with Free or Open Source software. You can see the actual code that ticks you off and make changes if necessary.

Compiling OpenSceneGraph on Windows

.. now, I’m using MinGW/MSYS (what’s the difference btw?) instead of Visual Studio. Apparently, those two can’t cope each other and since I’m gonna use Eclipse with MinGW/MSYS, I have to compile the OpenSceneGraph (OSG) with MinGW/MSYS too.

The good news is, OSG uses CMake. It helps a lot when dealing with many build system on many platforms (as long as it supports of course).

  1. First, prepare the ammunition. Download CMake, MinGW/MSYS, OSG, and also OSG’s required 3rdParty libraries. Installing CMake should be straight forward. But maybe not the case for MinGW and MSYS. I already forgot how to install it, so just ask Google for this one =D

  2. Extract the OSG somewhere, for example C:OpenSceneGraph-2.6.1OpenSceneGraph-2.6.1. I have it extracted there already, so I just use it. Also don’t forget to extract the 3rdParty bundle into C:OpenSceneGraph-2.6.13rdParty.

  3. Open CMake, point the source code directory to that directory, and also set the build directory if you don’t want to mess the source directory like me.

  4. Click the configure button and select MSYS Makefiles for the generator.

  5. CMake will then do the initial configuration. Adjust some configurations to fit your needs, such as CMAKE_INSTALL_PREFIX if you want to change the OSG installation directory.

    In my case, I also have to turn off the BUILD_OSG_PLUGINS option because it needs some other libraries which I don’t know. Since I just want to get the OSG compiled, it is easier for me to turn this one off rather than finding the libraries.

  6. Click the configure button again.. and maybe again.. until the OK button can get clicked.

  7. Finish the CMake by clicking the OK button. It will generate the requested build system.

  8. Open the MSYS console. Go to the OSG build directory and let the two left “magic commands” do their job. The “configure” part is already done by CMake.

    $ make
    

    and finally..

    $ make install
    
  9. Let your fingers crossed, grab some tea or coffee, and wait until the compilation ends (hopefully).

Then.. let the coding continues.. =)

Find the source code at http://gist.github.com/55138

Compiling OpenSceneGraph on Windows

.. now, I’m using MinGW/MSYS (what’s the difference btw?) instead of Visual Studio. Apparently, those two can’t cope each other and since I’m gonna use Eclipse with MinGW/MSYS, I have to compile the OpenSceneGraph (OSG) with MinGW/MSYS too.

The good news is, OSG uses CMake. It helps a lot when dealing with many build system on many platforms (as long as it supports of course).

  1. First, prepare the ammunition. Download CMake, MinGW/MSYS, OSG, and also OSG’s required 3rdParty libraries. Installing CMake should be straight forward. But maybe not the case for MinGW and MSYS. I already forgot how to install it, so just ask Google for this one =D

  2. Extract the OSG somewhere, for example C:OpenSceneGraph-2.6.1OpenSceneGraph-2.6.1. I have it extracted there already, so I just use it. Also don’t forget to extract the 3rdParty bundle into C:OpenSceneGraph-2.6.13rdParty.

  3. Open CMake, point the source code directory to that directory, and also set the build directory if you don’t want to mess the source directory like me.

  4. Click the configure button and select MSYS Makefiles for the generator.

  5. CMake will then do the initial configuration. Adjust some configurations to fit your needs, such as CMAKE_INSTALL_PREFIX if you want to change the OSG installation directory.

    In my case, I also have to turn off the BUILD_OSG_PLUGINS option because it needs some other libraries which I don’t know. Since I just want to get the OSG compiled, it is easier for me to turn this one off rather than finding the libraries.

  6. Click the configure button again.. and maybe again.. until the OK button can get clicked.

  7. Finish the CMake by clicking the OK button. It will generate the requested build system.

  8. Open the MSYS console. Go to the OSG build directory and let the two left “magic commands” do their job. The “configure” part is already done by CMake.

    $ make
    

    and finally..

    $ make install
    
  9. Let your fingers crossed, grab some tea or coffee, and wait until the compilation ends (hopefully).

Then.. let the coding continues.. =)

Find the source code at http://gist.github.com/55138

Widget Qt4 dan OpenSceneGraph

Kabarnya, widget Qt4 bisa digambar di atas layar OpenGL. Jadi kepikiran gmn caranya widget2 tsb bisa juga dipasang bareng dg OpenSceneGraph. Gugling sedikit, eh ternyata udah ada yang buat!. Walau sepertinya masih ada masalah.

Saya coba donlod kodingan yg dikasih. Lalu ubah2 dikit supaya bisa nampilin kubus. Jadi deh =D

Okeh.. saatnya bereksperimen lagi..

Kompilasi OpenSceneGraph di Windows

Saya make Visual C++ 2008 Express Edition yang bisa diunduh gratis. Trus siapin juga CMake yang akan dipakai tuk membuat berkas solution untuk Visual Studio.

Lalu..

  • Siapkan direktori untuk OpenSceneGraph, misalnya di C:OpenSceneGraph-2.6.1.
  • Unduh kode sumber OpenSceneGraph dan ekstrak ke C:OpenSceneGraph-2.6.1OpenSceneGraph.
  • Unduh pustaka lain yang dibutuhkan. Versi siap pakai bisa diunduh dalam satu paket dari website OpenSceneGraph (3rdParty_Win32binaries_2005_05_10.zip). Ekstrak ke C:OpenSceneGraph-2.6.13rdParty.
  • Jalankan CMake-GUI. Arahkan direktori berkas kode sumber (“Where is the source code”) ke direktori C:OpenSceneGraph-2.6.1OpenSceneGraph dan direktori hasil (“Where to build the binaries”) ke direktori pilihan Anda.

  • Klik tombol Configure. Pilih Visual Studio 9 2008 kalau ditanya generator yang akan digunakan. Atur konfigurasi lain yang ada kalau mau. Sudahi dengan mengklik tombol Generate.
  • Buka Visual C++ dan buka solution OpenSceneGraph yang terbentuk di dalam direktori binari pilihan Anda.
  • Pilih modus kompilasi, Debug atau Release. Lalu mulai kompilasi dengan mengklik menu Build » Build Solution

Setelah itu, silakan cari film atau makanan dan mulai nonton/makan karena proses kompilasi cukup memakan waktu 🙂

Referens: http://www.openscenegraph.org/projects/osg/wiki/Support/PlatformSpecifics/VisualStudio

Kompilasi OpenSceneGraph di Mac OS X

Siapin libraries lain yg dibutuhkan termasuk cmake lalu..

$ cmake ke/direktori/kodesumber/opensourcegraph 
  -DDEFAULT_GLU_TESS_CALLBACK_TRIPLEDOT=ON

Paramater -DDEFAULT_GLU_TESS_CALLBACK_TRIPLEDOT=ON itulah yg kudu ditambahin. Setelah itu, ya make dan make install deh..

Referensi: http://trac.macports.org/ticket/17294