mariokonrad / marnav

a library for MARitime NAVigation
Other
95 stars 48 forks source link

Early stage library call make wrong data for Visual Studio 2015 #8

Closed ShadowTeolog closed 6 years ago

ShadowTeolog commented 7 years ago

On early stage of application running global variables created and call this code, but static dictionary for 6-bit encoding still not ready, so code gives corrupted data without any error. This minor level bug, but can affect on some situations. Maybe exception on try to encode on not ready dictionary needed. class test { public: test(){ using namespace marnav; ais::message_14 broadcast; broadcast.set_mmsi(utils::mmsi(cs)); broadcast.set_repeat_indicator(IsRepeat); broadcast.set_text(AisSartMessage); auto payload = encode_message(broadcast); //this data broken } } test globalvariable;

Rasbats commented 6 years ago

Working on an OpenCPN simgame plugin, hopefully multi-platform. Tried to port to Windows using VS2015 but Windows does not have termios.h or unistd.h. Have you or ShadowTeolog made a Windows version of these utilities? I need to be able to write an AIS NMEA sentence from the data in VTG and GLL sentences.

Thanks. Mike E: miker(at symbol ...)members.swis.net

mariokonrad commented 6 years ago

No, Windows was never on my radar, so I never tried it.

You can however configure the library to not include the IO stuff. While configuring with cmake, add the option -DENABLE_IO=NO. If you really only need NMEA and AIS, I suggest you also disable SeaTalk with -DENABLE_SEATALK=NO.

It is also documented in README.md.

mariokonrad commented 6 years ago

Note: the two posts above are unrelated.

@ShadowTeolog : sorry for the long delay. Yes this does not work, because during encode_message the sixbit conversion is used, which uses a static constant table (std::vector<std::pair<>> to be precise). The order of initialization of static data is not specified. This is not a bug, because you cannot rely on order of initialization of static global data anyway. Maybe the table should not be a std::vector, need to test it...

ShadowTeolog commented 6 years ago

I understand why this happen with static member, singleton may help here, i think. I already know about windows is not in you priority, because library even not compile on VS without modifications of template code.Only add this issue for minor level notify.

mariokonrad commented 6 years ago

Yes, singletons would help... but I'm not a fan of them, trying to avoid them actually. I'll think about it...

Regarding Windows/VS builds, are there many changes? Which templates are affected? And there is the problem of which version of VS would the library need to support?

mariokonrad commented 6 years ago

Static initialization order for encoding/decoding of sixbit ASCII should be fixed now in the commit c8f1464. This should close the issue.