Closed loachfish closed 9 years ago
maybe it was caused as that not fill the field btnInfo.
So the case is that when the vector is not filled, it will crash to gen?
the function // Specialization of Print above for pointer types. template<> void Print<const void >(const void val, Type type, int indent, StructDef union_sd, const GeneratorOptions &opts, std::string _text); the val maybe nullptr, when the vector is not filled. when goto the function PrintVector, the pointer is nullptr.
So it add the condition: in the begine of function of Print if (val == nullptr) { return; }
it runs OK, but the output is like this: { layoutPattern: MasterSlave, layoutID: Slave, overwriteFlag: 1, cursorControlType: DestinationMode, btnCount: 0, btnInfo: }
maybe we should fill the meta text when the val == nullptr, to ensure the format.
are you using --defaults-json
? You adding || true
does something similar to my commit, except it doesn't check that the field is scalar, which doesn't surprise me that it would crash.
it works when add the options. flatbuffers::GeneratorOptions opts; opts.strict_json = true; opts.output_default_scalars_in_json = true; // key GenerateText(parser, fbs_str.c_str(), opts, &jsongen);
another syntax error when make in my env: flatbuffers/src/flathash.cpp:26:17: the enum items cannot end with a comma: enum OutputFormat { kDecimal, kHexadecimal, kHexadecimal0x, ///< };
Maybe it works well in some env, but it will affects the portability .
What compiler do you use, and what version?
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Ubuntu 12.04
the commit-ecf5a6a does not solve the situation thar when the field value is 0.
My problem is that, I just modify the FILE:idl_gen_text.cppfunction; FUNCTION:GenStruct() LINE: if (struct_def.fixed || table->CheckField(fd.value.offset)) { to if (struct_def.fixed || table->CheckField(fd.value.offset) || true) { to ensure the value will be printed, while in this case it crashed.
the version i am using is git clone in 2015/01/12.
// test case, it can also test for #209 /Screen.fbs/ namespace hw.Screen;
enum LayOutType:ubyte { Full = 0, MasterSlave = 1 }
enum LayOutID:ubyte { MasterOrFullScreen = 0, Slave = 1 }
enum CursorCtrlType:ubyte { AddressingMode = 0, DestinationMode = 1 }
table NDBtnInfo { ID:ubyte; zoneID:ubyte; focusType:ubyte; specialBit:ubyte; x:ushort; y:ushort; w:ushort; h:ushort; upperBtnID:ubyte; lowerBtnID:ubyte; leftBtnID:ubyte; rightBtnID:ubyte; }
table NDTouchCoordinate{ layoutPattern:LayOutType; layoutID:LayOutID; overwriteFlag:bool; cursorControlType:CursorCtrlType;
}
/_UTScreen.cpp/
include
include
include <sys/types.h>
include <sys/stat.h>
include
include
include
include
include "flatbuffers/flatbuffers.h"
include "flatbuffers/idl.h"
include "flatbuffers/util.h"
include "Screen_generated.h"
using namespace std; using namespace hw::Screen; using namespace flatbuffers;
ifndef NDEBUG
define NDEBUG
endif
int main(int argc, char* agrv[]) { std::vector orignal;
orignal.push_back(0x00);
orignal.push_back(0x01);
orignal.push_back(0x00);
orignal.push_back(0x01);
orignal.push_back(0x00);
orignal.push_back(0x00);
orignal.push_back(0x00);
orignal.push_back(0x00);
}
crash as signal 11 when gen struct about btnCount.