File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -380,12 +380,18 @@ int reb_simulation_reset_function_pointers(struct reb_simulation* const r){
380380}
381381
382382struct reb_simulation * reb_simulation_create (){
383+ struct reb_simulation * r = reb_simulation_try_create ();
384+ if (r == NULL ) reb_exit ("Memory allocation failed." );
385+ return r ;
386+ }
387+
388+ struct reb_simulation * reb_simulation_try_create (){
383389 struct reb_simulation * r = calloc (1 ,sizeof (struct reb_simulation ));
390+ if (r == NULL ) return NULL ;
384391 reb_simulation_init (r );
385392 return r ;
386393}
387394
388-
389395void reb_simulation_copy_with_messages (struct reb_simulation * r_copy , struct reb_simulation * r , enum reb_simulation_binary_error_codes * warnings ){
390396 char * bufp ;
391397 size_t sizep ;
Original file line number Diff line number Diff line change @@ -701,8 +701,10 @@ struct reb_simulation {
701701
702702// Simulation life cycle
703703
704- // Allocates memory for reb_simulation and initializes it.
704+ // Allocates memory for reb_simulation and initializes it. Fatal on allocation failure.
705705DLLEXPORT struct reb_simulation * reb_simulation_create (void );
706+ // Attempts to allocate memory for reb_simulation and initializes it. Returns NULL on allocation failure.
707+ DLLEXPORT struct reb_simulation * reb_simulation_try_create (void );
706708// Create a simulation object from a file. Set snapshot=-1 to load last snapshot.
707709DLLEXPORT struct reb_simulation * reb_simulation_create_from_file (char * filename , int64_t snapshot );
708710// Create a simulation object from a simulationarchive. Set snapshot=-1 to load last snapshot.
You can’t perform that action at this time.
0 commit comments