Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nlohmann JSON Parse crash with raylib-cpp #3570

Closed
2 tasks done
GalaxyGamingBoy opened this issue Jul 5, 2022 · 2 comments
Closed
2 tasks done

Nlohmann JSON Parse crash with raylib-cpp #3570

GalaxyGamingBoy opened this issue Jul 5, 2022 · 2 comments
Labels
solution: invalid the issue is not related to the library

Comments

@GalaxyGamingBoy
Copy link

Description

I am trying to run this code and it crashes with this error:
make: *** [Makefile:98: execute] Error 3
I am using raylib-cpp and json by nlohmann.
The nlohmann .hpp file is on include/nlohmann folder.
It crashes on line 11 specifically. I have also tried changing it to settings = nlohmann::json::parse(settings_file)

Reproduction steps

On command prompt make

Expected vs. actual results

Expected:
The app window pop-ups

Actual:
Make crashes

Minimal code example

#include <iostream>
#include <fstream>
#include <raylib-cpp.hpp>

#include "nlohmann/json.hpp"

int main(int argc, const char** argv) {
    // Initialization
    nlohmann::json settings;
    std::ifstream settings_file("settings.json");
    settings_file >> settings; // Line 11 - Crashes Here
    settings_file.close();

    raylib::Window win(800, 600, "Test");
    SetTargetFPS(60);

    // Main game loop
    while (!win.ShouldClose())
    {
        // Update

        // Draw
        BeginDrawing();
        ClearBackground(RAYWHITE);
        EndDrawing();
    }

    return 0;
}

With this make file

# Copyright (c) 2020 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
#
# This code is released under an unmodified zlib license.
# For conditions of distribution and use, please see:
#     https://opensource.org/licenses/Zlib

# Define custom functions
rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
platformpth = $(subst /,$(PATHSEP),$1)

# Set global macros
buildDir := bin
executable := app
target := $(buildDir)/$(executable)
sources := $(call rwildcard,src/,*.cpp)
objects := $(patsubst src/%, $(buildDir)/%, $(patsubst %.cpp, %.o, $(sources)))
depends := $(patsubst %.o, %.d, $(objects))
compileFlags := -std=c++17 -I include
linkFlags = -L lib/$(platform) -l raylib

# Check for Windows
ifeq ($(OS), Windows_NT)
	# Set Windows macros
	platform := Windows
	CXX ?= g++
	linkFlags += -Wl,--allow-multiple-definition -pthread -lopengl32 -lgdi32 -lwinmm -mwindows -static -static-libgcc -static-libstdc++
	libGenDir := src
	THEN := &&
	PATHSEP := \$(BLANK)
	MKDIR := -mkdir -p
	RM := -del /q
	COPY = -robocopy "$(call platformpth,$1)" "$(call platformpth,$2)" $3
else
	# Check for MacOS/Linux
	UNAMEOS := $(shell uname)
	ifeq ($(UNAMEOS), Linux)
		# Set Linux macros
		platform := Linux
		CXX ?= g++
		linkFlags += -l GL -l m -l pthread -l dl -l rt -l X11
	endif
	ifeq ($(UNAMEOS), Darwin)
		# Set macOS macros
		platform := macOS
		CXX ?= clang++
		linkFlags += -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL
		libGenDir := src
	endif

	# Set UNIX macros
	THEN := ;
	PATHSEP := /
	MKDIR := mkdir -p
	RM := rm -rf
	COPY = cp $1$(PATHSEP)$3 $2
endif

# Lists phony targets for Makefile
.PHONY: all setup submodules execute clean

# Default target, compiles, executes and cleans
all: $(target) execute clean

# Sets up the project for compiling, generates includes and libs
setup: include lib

# Pull and update the the build submodules
submodules:
	git submodule update --init --recursive

# Copy the relevant header files into includes
include: submodules
	$(MKDIR) $(call platformpth, ./include)
	$(call COPY,vendor/raylib-cpp/vendor/raylib/src,./include,raylib.h)
	$(call COPY,vendor/raylib-cpp/vendor/raylib/src,./include,raymath.h)
	$(call COPY,vendor/raylib-cpp/include,./include,*.hpp)

# Build the raylib static library file and copy it into lib
lib: submodules
	cd vendor/raylib-cpp/vendor/raylib/src $(THEN) "$(MAKE)" PLATFORM=PLATFORM_DESKTOP
	$(MKDIR) $(call platformpth, lib/$(platform))
	$(call COPY,vendor/raylib-cpp/vendor/raylib/$(libGenDir),lib/$(platform),libraylib.a)

# Link the program and create the executable
$(target): $(objects)
	$(CXX) $(objects) -o $(target) $(linkFlags)

# Add all rules from dependency files
-include $(depends)

# Compile objects to the build directory
$(buildDir)/%.o: src/%.cpp Makefile
	$(MKDIR) $(call platformpth, $(@D))
	$(CXX) -MMD -MP -c $(compileFlags) $< -o $@ $(CXXFLAGS)

# Run the executable
execute:
	$(target) $(ARGS)

# Clean up all relevant files
clean:
	$(RM) $(call platformpth, $(buildDir)/*)


### Error messages

```Shell
mkdir -p  bin
g++ -MMD -MP -c -std=c++17 -I include src/main.cpp -o bin/main.o 
g++  bin/main.o -o bin/app -L lib/Windows -l raylib -Wl,--allow-multiple-definition -pthread -lopengl32 -lgdi32 -lwinmm -mwindows -static -static-libgcc -static-libstdc++
bin/app 
make: *** [Makefile:98: execute] Error 3

Compiler and operating system

G++ Windows

Library version

3.10.5

Validation

@nlohmann
Copy link
Owner

nlohmann commented Jul 5, 2022

What does "crash" mean? A signal? An exception? Can you run in a debugger and provide a stacktrace? Can you make sure file settings.json is in the work directory, is readable by the process and is valid JSON?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Jul 5, 2022
@GalaxyGamingBoy
Copy link
Author

Nevermind, fixed it. It was an error 101

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug state: needs more info the author of the issue needs to provide more details labels Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants