{"record":{"id":"a7517b5c592fa30b","repo":"DrKLO/Telegram","slug":"failed-to-create-a-mode-n","errorCode":null,"errorMessage":"failed to create a mode\\n","messagePattern":"failed to create a mode\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/celt/opus_custom_demo.c","lineNumber":76,"sourceCode":"#endif\n   int count = 0;\n   opus_int32 skip;\n   opus_int16 *in, *out;\n   if (argc != 9 && argc != 8 && argc != 7)\n   {\n      fprintf (stderr, \"Usage: test_opus_custom <rate> <channels> <frame size> \"\n               \" <bytes per packet> [<complexity> [packet loss rate]] \"\n               \"<input> <output>\\n\");\n      return 1;\n   }\n\n   rate = (opus_int32)atol(argv[1]);\n   channels = atoi(argv[2]);\n   frame_size = atoi(argv[3]);\n   mode = opus_custom_mode_create(rate, frame_size, NULL);\n   if (mode == NULL)\n   {\n      fprintf(stderr, \"failed to create a mode\\n\");\n      return 1;\n   }\n\n   bytes_per_packet = atoi(argv[4]);\n   if (bytes_per_packet < 0 || bytes_per_packet > MAX_PACKET)\n   {\n      fprintf (stderr, \"bytes per packet must be between 0 and %d\\n\",\n                        MAX_PACKET);\n      return 1;\n   }\n\n   inFile = argv[argc-2];\n   fin = fopen(inFile, \"rb\");\n   if (!fin)\n   {\n      fprintf (stderr, \"Could not open input file %s\\n\", argv[argc-2]);\n      return 1;\n   }","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/celt/opus_custom_demo.c#L58-L94","documentation":"opus_custom_mode_create(rate, frame_size, NULL) returned NULL — Opus could not build a custom mode for the given sample rate and frame size. The custom mode is the prerequisite for both encoder and decoder creation, so nothing else can proceed.","triggerScenarios":"Passing an invalid rate or frame_size combination. opus_custom_mode_create requires specific constraints: rate typically 8000–48000, frame_size must fit the mode's internal CELT layout (e.g. multiples of the MDCT window / 2.5ms sub-frames), and the product must be representable. NULL is also returned on internal allocation failure.","commonSituations":"Using a frame size not supported by the custom CELT mode (e.g. non-multiple of 120 at 48kHz); an unsupported rate like 22050; passing 0 or negative values via atol on a malformed CLI arg; opus built without CUSTOM_MODES so the API rejects custom configs.","solutions":["Use a rate/frame_size pair known valid for CELT custom mode (e.g. 48000 with frame_size in {120, 240, 480, 960, 1920, 2880}).","Check that the build defines CUSTOM_MODES; without it opus_custom_mode_create always returns NULL.","Validate argv values are positive integers before calling atol.","Inspect the error* out-param (here passed as NULL) — pass a non-NULL int* to get the specific OPUS_BAD_ARG / allocation code."],"exampleFix":"// before\nmode = opus_custom_mode_create(rate, frame_size, NULL);\nif (mode == NULL) { fprintf(stderr, \"failed to create a mode\\n\"); return 1; }\n\n// after: capture the error code\nint mode_err = 0;\nmode = opus_custom_mode_create(rate, frame_size, &mode_err);\nif (mode == NULL) { fprintf(stderr, \"failed to create a mode: %s\\n\", opus_strerror(mode_err)); return 1; }","handlingStrategy":"validation","validationCode":"// Pass a real error out-param and validate rate/frame_size first.\nif (rate <= 0 || frame_size <= 0) { fprintf(stderr, \"rate and frame_size must be positive\\n\"); return 1; }\nint mode_err = OPUS_OK;\nmode = opus_custom_mode_create(rate, frame_size, &mode_err);\nif (mode == NULL) { fprintf(stderr, \"failed to create a mode: %s\\n\", opus_strerror(mode_err)); return 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm the opus build defines CUSTOM_MODES.","Use rate/frame_size pairs known valid for CELT (e.g. 48000 with multiples of 120).","Always pass a non-NULL error out-param to opus_custom_mode_create for diagnostics."],"tags":["opus","celt","custom-mode","configuration","audio","c"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}