xcode crashes after trying to build my code for a second time

Hello,

I have recently started coding in c++, using xcode's command line tool (university project). Ever since I started using this Apple made app on my 2022 macbook air M2, I am battling a major issue. Every time I try to either build my project for the second time or to clear the console, after I have made some input through the console, the Xcode crashes. I've been looking for the solution for weeks now, even reinstalled the whole xcode app, but nothing helped. I will be very much grateful for any suggestions... thanks. Here is one of my codes, where the issue appears:

// Hlavickove soubory
#include <stdlib.h>  // Standardni knihovna
#include <stdio.h>   // Standardni input, output
#include <math.h>    // Matematicka knihovna

#define N_MAX 100

// Samotny program
int main()      // Zahlavi hlavni funkce
{
    int n, max, i, souradnice_je_0;         // Definice promennych a jejich nastaveni do vychozich hodnot
    float a[N_MAX], ap, gp, hp;
    souradnice_je_0 = 1;
    max = 100;
    ap = 0;
    gp = 1;
    hp = 0;
    
Znovu:
    
    printf("\n Zadej dimenzi vektoru n: ");
    scanf("%i", &n);        // Zadani poctu dimenzi
    
    if(n>N_MAX)     // Osetreni maxima dimenzi
    {
        printf("\n Chyba v datech: Zadaná dimenze n musí být menší než %i", max);
        goto Znovu;
    }
    else if(n<=0)     // Osetreni kladnosti dimenzi
    {
        printf("\n Chyba v datech: Zadaná dimenze n musí být větší než 0");
        goto Znovu;
    }
    else
    {
        if(n == 1)        // Kontrola gramatiky:Dd
        {
            printf("\n Vektor má %i dimenzi", n);
        }
        else if(n>1 and n<5)
        {
            printf("\n Vektor má %i dimenze", n);
        }
        else
        {
            printf("\n Vektor má %i dimenzí", n);
        }
    }
    
    for(i = 0; i < n; i++)      // Zadani souradnic vektoru
    {
        printf("\n Zadej hodnotu x[%i] souřadnici vektoru: ", i);
        scanf("%f", &a[i]);
        printf("x[%i] = %g",i, a[i]);
        if(a[i] == 0)         // Kontrola zda a[i] je 0 kvuli h.p.
        {
            ap = ap + a[i];     // Arit. prumer 1. cast
            gp = gp * a[i];     // Geom. prumer 1. cast
            souradnice_je_0 = 0;       // Switch kvuli deleni nulou
        }
        else
        {
            ap = ap + a[i];           // Arit. prumer 1. cast
            gp = gp * a[i];           // Geom. prumer 1. cast
            hp = hp + (1 / a[i]);     // Harm. prumer 1. cast
        }
    }
    if(hp==0)
    {
        souradnice_je_0 = 0;       // Switch kvuli deleni nulou
    }
    
    ap = ap /n;           // Arit. prumer 2. cast
    printf("\n Aritmeticky prumer je: %g", ap);
    
    if(gp>=0)           // Nelze odmocnit zaporne cislo
    {
        gp = pow(gp, 1./n);     // Geom. prumer 2. cast
    }
    
    if(gp>=0)
    {
        printf("\n Geometricky prumer je: %g", gp);
    }
    else
    {
        printf("\n Geometricky prumer neni pro zadany vektor definovan");
    }
    
    if(souradnice_je_0 == 0)
    {
        printf("\n Harmonicky prumer neni pro zadany vektor definovan \n");
    }
    else
    {
        hp = n / hp;        // Harm. prumer 2. cast
        printf("\n Harmonicky prumer je: %g \n", hp);
    }
   
    return 0;
}

after I have made some input through the console, the Xcode crashes.

So Xcode itself is crashing? That’s not good.

That crash should generate a crash report. Please post an example here, using the instructions in Posting a Crash Report. That might give us a hint as to where things are going wrong in Xcode.

If you create a new project from the macOS > Command Line Tool template, does it crash? Does that change if you modify your project to read a value from the console? So, something like this:

std::cout << "Hello, World!\n";
int n = 0;
scanf("%i", &n);
std::cout << n << std::endl;

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I can't seem to be able to attach the file to my original post.

Generally one just posts a reply with it as an attachment.

[Fexe sent me the crash report via another channel so I’m replying based on that.]

The crash report shows this:

Application Specific Backtrace 0:
0   CoreFoundation    … __exceptionPreprocess + 176
1   DVTFoundation     … DVTFailureHintExceptionPreprocessor + 388
2   libobjc.A.dylib   … objc_exception_throw + 60
3   CoreFoundation    … -[__NSCFString characterAtIndex:].cold.1 + 0
4   CoreFoundation    … -[NSConstantDictionary objectForKey:] + 0
5   SourceEditor      … $s12SourceEditor0ab4DataA0C17deleteTextInRangeyAA0aB8PositionVSnyAFGF + 2300
6   IDEConsoleKit     … $s13IDEConsoleKit0A4ViewC21removeAllConsoleItems33_16D2ADED863F10BE3A741D5B18B494B7LLyy…
7   IDEConsoleKit     … $s13IDEConsoleKit0A4ViewC10setMatchesyySaySo0A4ItemCGF + 712
8   IDEConsoleKit     … $s13IDEConsoleKit0A13FilterManagerC13filterConsole33_2971D1EE5E4DDD5D099E1A896C78B97ALL…
9   IDEConsoleKit     … $sIeg_IeyB_TR + 28
10  DVTFoundation     … $sIeg_IeyB_TR + 28
11  DVTFoundation     … __DVT_CALLING_CLIENT_BLOCK__ + 16
12  DVTFoundation     … __DVTDispatchAsync_block_invoke + 48
13  libdispatch.dylib … _dispatch_call_block_and_release + 32

This is clearly related to Xcode’s text editor. That’s interesting, but not helpful.

Anyway, you should definitely file a bug against Xcode about this. Please post your bug number, just for the record.

As to how to get around this, you didn’t answer my earlier question:

If you create a new project from the macOS > Command Line Tool template, does it crash? Does that change if you modify your project to read a value from the console?

Also, try creating a new local user on your Mac and see if the problem reproduces there. That’ll tell you whether the issue is tied to your user account for some reason.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi,

so, I have just tested the trick with the new user. Unfortunately the issue is the same:/.

To reply your question: When I create a new short project, even if it reads one value from the console, everything is fine. The issue appears only when working with longer and more complex as the one I have provided earlier.

I have filed a bug number FB13394560 with no answer so far...

Any other ideas?:D

Thanks again, I hope to hear from you soon. ŠP - mail:"petru."+"simoun"+"@gmail.com"

xcode crashes after trying to build my code for a second time
 
 
Q