浏览代码

Letting dsrMain be void for simplicity and safety.

David Piuva 3 年之前
父节点
当前提交
964425ce79

+ 5 - 11
Source/DFPSR/api/fileAPI.h

@@ -100,28 +100,22 @@ namespace dsr {
 
 	// DSR_MAIN_CALLER is a convenient wrapper for getting input arguments as a list of portable Unicode strings.
 	//   The actual main function gets placed in DSR_MAIN_CALLER, which calls the given function.
-	// When a regular function replaces the main function, it will not return zero by default.
-	//   Returning something else than zero tells that something went wrong and it must skip cleanup in order to get out.
-	//   Then the window and other resources held as global variables might not close.
 	// Example:
 	//   DSR_MAIN_CALLER(dsrMain)
-	//   int dsrMain(List<String> args) {
+	//   void dsrMain(List<String> args) {
 	//       printText("Input arguments:\n");
 	//       for (int a = 0; a < args.length(); a++) {
 	//           printText("  args[", a, "] = ", args[a], "\n");
 	//       }
-	//       return 0;
 	//   }
 	#ifdef USE_MICROSOFT_WINDOWS
 		#define DSR_MAIN_CALLER(MAIN_NAME) \
-			int MAIN_NAME(List<String> args); \
-			int main() { \
-				return MAIN_NAME(file_impl_getInputArguments()); \
-			}
+			void MAIN_NAME(List<String> args); \
+			int main() { MAIN_NAME(file_impl_getInputArguments()); return 0; }
 	#else
 		#define DSR_MAIN_CALLER(MAIN_NAME) \
-			int MAIN_NAME(List<String> args); \
-			int main(int argc, char **argv) { return MAIN_NAME(file_impl_convertInputArguments(argc, (void**)argv)); }
+			void MAIN_NAME(List<String> args); \
+			int main(int argc, char **argv) { MAIN_NAME(file_impl_convertInputArguments(argc, (void**)argv)); return 0; }
 	#endif
 	// Helper functions have to be exposed for the macro handle your input arguments.
 	//   Do not call these yourself.

+ 1 - 4
Source/SDK/cube/main.cpp

@@ -49,7 +49,7 @@ Model createCubeModel(const FVector3D &min, const FVector3D &max) {
 }
 
 DSR_MAIN_CALLER(dsrMain)
-int dsrMain(List<String> args) {
+void dsrMain(List<String> args) {
 	// Create a window
 	window = window_create(U"David Piuva's Software Renderer - Cube example", 1600, 900);
 	// Load an interface to the window
@@ -182,7 +182,4 @@ int dsrMain(List<String> args) {
 
 		window_showCanvas(window);
 	}
-
-	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
-	return 0;
 }

+ 1 - 3
Source/SDK/fileFinder/main.cpp

@@ -28,7 +28,7 @@ void exploreFolder(const ReadableString& folderPath, const ReadableString& inden
 }
 
 DSR_MAIN_CALLER(dsrMain)
-int dsrMain(List<String> args) {
+void dsrMain(List<String> args) {
 	printText("Input arguments:\n");
 	for (int a = 0; a < args.length(); a++) {
 		printText("  args[", a, "] = ", args[a], "\n");
@@ -49,6 +49,4 @@ int dsrMain(List<String> args) {
 		exploreFolder(currentPath, U"");
 	}
 	*/
-	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
-	return 0;
 }

+ 1 - 4
Source/SDK/guiExample/main.cpp

@@ -12,7 +12,7 @@ Component buttonAdd;
 Component myListBox;
 
 DSR_MAIN_CALLER(dsrMain)
-int dsrMain(List<String> args) {
+void dsrMain(List<String> args) {
 	// Set current path to the application folder, so that it's safe to use relative paths for loading GUI resources.
 	// Loading and saving files will automatically convert / and \ to the local format using file_optimizePath, so that you can use them directly in relative paths.
 	file_setCurrentPath(file_getApplicationFolder());
@@ -78,7 +78,4 @@ int dsrMain(List<String> args) {
 		// Show the final image
 		window_showCanvas(window);
 	}
-
-	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
-	return 0;
 }

+ 1 - 4
Source/SDK/terrain/main.cpp

@@ -315,7 +315,7 @@ bool showBuffers = false;
 Window window;
 
 DSR_MAIN_CALLER(dsrMain)
-int dsrMain(List<String> args) {
+void dsrMain(List<String> args) {
 	// Create a window
 	window = window_create(U"David Piuva's Software Renderer - Terrain example", 1600, 900);
 
@@ -432,7 +432,4 @@ int dsrMain(List<String> args) {
 	}
 
 	printText("\nTerminating the application.\n");
-
-	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
-	return 0;
 }

+ 1 - 4
Source/templates/basic3D/main.cpp

@@ -61,7 +61,7 @@ Model createCubeModel(const FVector3D &min, const FVector3D &max) {
 }
 
 DSR_MAIN_CALLER(dsrMain)
-int dsrMain(List<String> args) {
+void dsrMain(List<String> args) {
 	// Create a window
 	window = window_create(U"Basic 3D template", 1600, 900);
 
@@ -121,7 +121,4 @@ int dsrMain(List<String> args) {
 
 		window_showCanvas(window);
 	}
-
-	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
-	return 0;
 }

+ 1 - 4
Source/templates/basicCLI/main.cpp

@@ -4,10 +4,7 @@
 using namespace dsr;
 
 DSR_MAIN_CALLER(dsrMain)
-int dsrMain(List<String> args) {
+void dsrMain(List<String> args) {
 	// Printing some text to the terminal.
 	printText(U"Hello world\n");
-
-	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
-	return 0;
 }

+ 1 - 4
Source/templates/basicGUI/main.cpp

@@ -21,7 +21,7 @@ bool running = true;
 Window window;
 
 DSR_MAIN_CALLER(dsrMain)
-int dsrMain(List<String> args) {
+void dsrMain(List<String> args) {
 	// Create a window
 	window = window_create(U"GUI template", 1000, 700);
 
@@ -54,7 +54,4 @@ int dsrMain(List<String> args) {
 		// Show the final image
 		window_showCanvas(window);
 	}
-
-	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
-	return 0;
 }