Help Porting OpenFL to GCW-Zero

./HelloWorld 
Main.hx:15: Hello World
Segmentation fault

Even removing the render method I get the same result. I think my lime.ndll is broken…

package;
import lime.app.Application;

class Main extends Application {
    public function new () {
        super ();
        trace ("Hello World");
    }
}

Great! Well this is a lot farther than most ports get at first. So it gets to the point of creating the application, umm, perhaps you could add trace messages into the Application class (or in the lime._backend.native.NativeApplication class) to get an idea of what things are firing, perhaps even in the C++ of the native backend, to get an idea of what is firing properly, and what is triggering a segmentation fault

1 Like

Some - but not all - segmentation faults can be debugged by defining HXCPP_STACK_LINE and HXCPP_CHECK_POINTER, as described here.

1 Like

Problem found: SDL can’t init in SDLApplication.cpp

    if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0 ) {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }

returns

Main.hx:15: Hello World
Unable to init SDL: SDL not built with timer support

Which does not make any sense, since the timer normally works in other applications. If I remove SDL_INIT_TIMER:

Main.hx:15: Hello World
Unable to init SDL: No available video device

Still no sense to me :stuck_out_tongue:

Thank you for your tips, guys.

A green screen, finally :smile:

1 Like

if you manage to do the port I buy one :slight_smile:

1 Like

@RafaelOliveira I hope so :smile:

One more mistery: building HelloWorld project in debug mode everything runs fine, but if I rebuild it in release mode I get ‘Illegal instruction’…

What was the fix for SDL init? Was it a linker flag or something?

Can you tell when the “Illegal instruction” occurs? Is this before it even executes the C++ application code?

I forgot to not use the native SDL toolkit, so the following line on Build.xml fixed it:

<files id="native-toolkit-sdl" if="LIME_SDL" unless="emscripten || gcw0" />

It occurs exactly after execution, before the “Hello World” trace. I’ll try to put some printfs on the C++ code. If I use gdb I can’t get anything as I don’t have debug info, but if I build with debug info there’s no errors o.O

Maybe you could use a try catch in the constructor

After some hacking in hxcpp I was able to use gdb:

(gdb) bt full
#0  lime::math::_ColorMatrix::ColorMatrix_Impl__obj::__boot ()
    at ./src/lime/math/_ColorMatrix/ColorMatrix_Impl_.cpp:651
No locals.
#1  0x77279224 in __boot_all () at ./src/__boot__.cpp:331
No locals.
#2  0x77147070 in main (argc=<optimized out>, argv=<optimized out>)
    at ./src/__main__.cpp:10
        t0 = 99

Taking a look at the cpp generated code:

void ColorMatrix_Impl__obj::__boot()
{
    __identity= Array_obj< Float >::__new().Add(1.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(1.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(1.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(1.0).Add(0.0);
}

I just don’t get what could be wrong there :frowning:

What is the difference between debug and release in your build flags? Can you build with Haxe release code and C++ debug args, and get it to work?

Using C++ debug args (-g, no strip, no optimizations flag, etc) still getting illegal instruction. It only works passing -debug to lime.

Hmm, so perhaps something triggered by the HXCPP debug flags

1 Like

Yeah, I think so. I’ll investigate this. Thanks again :smile:

I was doing some tests with several hxcpp parameters, but I could not come to any conclusion.
A strange discovery, however, was as follows: starting vector __identity empty on the file lime/math/ColorMatrix.hx the release version works normally.

abstract ColorMatrix(Float32Array) from Float32Array to Float32Array {
    
#if gcw0    
    private static var __identity = [ ];
#else
    private static var __identity = [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ];
#end

I don’t know why o.O

Edit: Testing the SimpleImage demo, I’m getting illegal instruction here (generated cpp):

void Matrix4_Impl__obj::__boot()
{
    __identity= Array_obj< Float >::__new().Add(1.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(1.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(1.0).Add(0.0).Add(0.0).Add(0.0).Add(0.0).Add(1.0);
}

I’ll take a look on lime/utils/Float32Array.hx

Could you later try with Luxe Engine? I have interest in this library too, and maybe it could help with your tests, it uses hxcpp too.